if (!sdl.audio_active)
return -1;
sdl.frequency = frequency;
- sound_create_square_wave((unsigned short *)sdl.audio_data,
+ sound_create_square_wave(22050, (unsigned short *)sdl.audio_data,
sdl.audio_size, frequency);
sdl.audio_pos = 0;
SDL_PauseAudio(0);
return -1;
}
- sound_create_square_wave((unsigned short *)data,
+ sound_create_square_wave(g_i2stx_pri.samplingrate,
+ (unsigned short *)data,
data_size / sizeof(unsigned short),
frequency);
#include <common.h>
#include <sound.h>
-void sound_create_square_wave(unsigned short *data, int size, uint32_t freq)
+void sound_create_square_wave(uint sample_rate, unsigned short *data, int size,
+ uint freq)
{
- const int sample = 48000;
const unsigned short amplitude = 16000; /* between 1 and 32767 */
- const int period = freq ? sample / freq : 0;
+ const int period = freq ? sample_rate / freq : 0;
const int half = period / 2;
assert(freq);
/*
* Generates square wave sound data for 1 second
*
+ * @param sample_rate Sample rate in Hz
* @param data data buffer pointer
* @param size size of the buffer
* @param freq frequency of the wave
*/
-void sound_create_square_wave(unsigned short *data, int size, uint32_t freq);
+void sound_create_square_wave(uint sample_rate, unsigned short *data, int size,
+ uint freq);
/*
* Initialises audio sub system