Skip to content

Commit daaa27d

Browse files
IceDragon200Blaž Hrastnik
authored andcommitted
modules/audio-libsoundio: Code gardening
1 parent fb618d6 commit daaa27d

5 files changed

Lines changed: 46 additions & 46 deletions

File tree

modules/audio-libsoundio/include/moon/audio/libsoundio/music.hxx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ namespace Moon
1212
class Music : public Source {
1313
public:
1414
Music(const std::string filename);
15-
~Music();
15+
virtual ~Music();
1616

1717
int read(float* dst, int frames);
1818

modules/audio-libsoundio/include/moon/audio/libsoundio/sound.hxx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ namespace Moon
1212
class Sound : public Source {
1313
public:
1414
Sound(const std::string filename);
15-
~Sound();
15+
virtual ~Sound();
1616

1717
int read(float* dst, int frames);
1818

modules/audio-libsoundio/src/mixer.cxx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,16 @@ namespace Moon {
77
void Mixer::mix(struct SoundIoChannelArea *areas, const struct SoundIoChannelLayout &layout, const float sampleRate, unsigned int frames)
88
{
99
// silence the buffer first
10-
for (size_t channel = 0; channel < layout.channel_count; ++channel) {
10+
for (int channel = 0; channel < layout.channel_count; ++channel) {
1111
memset(areas[channel].ptr, 0, areas[channel].step * frames);
1212
}
1313
for(auto const& handle: handles) {
1414
handle->mix(areas, layout, sampleRate, frames);
1515
}
1616

1717
// clipping, to avoid overdrive
18-
for (int frame = 0; frame < frames; ++frame) {
19-
for (size_t channel = 0; channel < layout.channel_count; ++channel) {
18+
for (size_t frame = 0; frame < frames; ++frame) {
19+
for (int channel = 0; channel < layout.channel_count; ++channel) {
2020
float* buffer = (float*)(areas[channel].ptr + areas[channel].step * frame);
2121
float sample = *buffer;
2222
*buffer = sample > 1.0f ? 1.0f : (sample < -1.0f ? -1.0f : sample);

modules/audio-libsoundio/src/mrb_moon_audio.cxx

Lines changed: 36 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -7,51 +7,51 @@
77
static mrb_value
88
audio_update(mrb_state *mrb, mrb_value klass)
99
{
10-
Moon::Audio::Update();
11-
return klass;
10+
Moon::Audio::Update();
11+
return klass;
1212
}
1313

1414
MOON_C_API void
1515
mrb_mruby_moon_audio_libsoundio_gem_init(mrb_state* mrb)
1616
{
17-
struct RClass *moon_module = mrb_define_module(mrb, "Moon");
18-
struct RClass *audio_module = mrb_define_module_under(mrb, moon_module, "Audio");
19-
struct RClass *audio_error = mrb_define_class_under(mrb, moon_module, "AudioError", E_RUNTIME_ERROR);
20-
mrb_define_class_method(mrb, audio_module, "update", audio_update, MRB_ARGS_NONE());
21-
//mmrb_sound_buffer_init(mrb, moon_module);
22-
mmrb_music_init(mrb, moon_module);
23-
mmrb_sound_init(mrb, moon_module);
17+
struct RClass *moon_module = mrb_define_module(mrb, "Moon");
18+
struct RClass *audio_module = mrb_define_module_under(mrb, moon_module, "Audio");
19+
struct RClass *audio_error = mrb_define_class_under(mrb, moon_module, "AudioError", E_RUNTIME_ERROR);
20+
mrb_define_class_method(mrb, audio_module, "update", audio_update, MRB_ARGS_NONE());
21+
//mmrb_sound_buffer_init(mrb, moon_module);
22+
mmrb_music_init(mrb, moon_module);
23+
mmrb_sound_init(mrb, moon_module);
2424

25-
const Moon::Audio::ErrorCode err = Moon::Audio::Initialize();
26-
switch (err) {
27-
case Moon::Audio::ErrorCode::MOON_AUDIO_CREATE_ERROR:
28-
mrb_raise(mrb, audio_error, "Underlying backend could not be created");
29-
break;
30-
case Moon::Audio::ErrorCode::MOON_AUDIO_CONNECTION_ERROR:
31-
mrb_raise(mrb, audio_error, "Could not estabish connection to backend");
32-
break;
33-
case Moon::Audio::ErrorCode::MOON_AUDIO_NO_DEVICE:
34-
mrb_raise(mrb, audio_error, "No default device present");
35-
break;
36-
case Moon::Audio::ErrorCode::MOON_AUDIO_DEVICE_MISSING:
37-
mrb_raise(mrb, audio_error, "Default device is missing");
38-
break;
39-
case Moon::Audio::ErrorCode::MOON_AUDIO_COULD_NOT_OPEN_STREAM:
40-
mrb_raise(mrb, audio_error, "Output stream could not be opened, does the selected device support it?");
41-
break;
42-
case Moon::Audio::ErrorCode::MOON_AUDIO_STREAM_CHANNEL_LAYOUT_ERROR:
43-
mrb_raise(mrb, audio_error, "Channel layout is invalid for the stream");
44-
break;
45-
case Moon::Audio::ErrorCode::MOON_AUDIO_STREAM_START_ERROR:
46-
mrb_raise(mrb, audio_error, "Stream could not be started");
47-
break;
48-
default:
49-
break;
50-
}
25+
const Moon::Audio::ErrorCode err = Moon::Audio::Initialize();
26+
switch (err) {
27+
case Moon::Audio::ErrorCode::MOON_AUDIO_CREATE_ERROR:
28+
mrb_raise(mrb, audio_error, "Underlying backend could not be created");
29+
break;
30+
case Moon::Audio::ErrorCode::MOON_AUDIO_CONNECTION_ERROR:
31+
mrb_raise(mrb, audio_error, "Could not estabish connection to backend");
32+
break;
33+
case Moon::Audio::ErrorCode::MOON_AUDIO_NO_DEVICE:
34+
mrb_raise(mrb, audio_error, "No default device present");
35+
break;
36+
case Moon::Audio::ErrorCode::MOON_AUDIO_DEVICE_MISSING:
37+
mrb_raise(mrb, audio_error, "Default device is missing");
38+
break;
39+
case Moon::Audio::ErrorCode::MOON_AUDIO_COULD_NOT_OPEN_STREAM:
40+
mrb_raise(mrb, audio_error, "Output stream could not be opened, does the selected device support it?");
41+
break;
42+
case Moon::Audio::ErrorCode::MOON_AUDIO_STREAM_CHANNEL_LAYOUT_ERROR:
43+
mrb_raise(mrb, audio_error, "Channel layout is invalid for the stream");
44+
break;
45+
case Moon::Audio::ErrorCode::MOON_AUDIO_STREAM_START_ERROR:
46+
mrb_raise(mrb, audio_error, "Stream could not be started");
47+
break;
48+
default:
49+
break;
50+
}
5151
}
5252

5353
MOON_C_API void
5454
mrb_mruby_moon_audio_libsoundio_gem_final(mrb_state* mrb)
5555
{
56-
Moon::Audio::Terminate();
56+
Moon::Audio::Terminate();
5757
}

modules/audio-libsoundio/src/sound.cxx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@ namespace Moon
66
Sound::Sound(const std::string filename)
77
{
88
SndfileHandle file(filename, SFM_READ);
9-
printf("Opened file '%s'\n", filename.c_str());
10-
printf(" Sample rate : %d\n", file.samplerate ());
9+
printf("Opened file '%s'\n", filename.c_str());
10+
printf(" Sample rate : %d\n", file.samplerate ());
1111
printf(" Channels : %d\n", file.channels ());
12-
printf(" Frames : %d\n", file.frames());
12+
printf(" Frames : %ld\n", file.frames());
1313

1414
m_channels = file.channels();
1515
m_sampleRate = file.samplerate();
@@ -30,11 +30,11 @@ namespace Moon
3030
}
3131

3232
int Sound::channels() {
33-
return m_channels;
33+
return m_channels;
3434
}
3535

3636
int Sound::sampleRate() {
37-
return m_sampleRate;
37+
return m_sampleRate;
3838
}
3939

4040
// returns how many frames we actually read

0 commit comments

Comments
 (0)