From 4f3ea475b0c72cf83175cc69bdd128b7a306523b Mon Sep 17 00:00:00 2001 From: chai Date: Sun, 27 May 2018 17:39:09 +0800 Subject: =?UTF-8?q?=E6=9B=B4=E6=96=B0=E9=9F=B3=E9=A2=91=E6=A8=A1=E5=9D=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- test/load wav.cpp | 65 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) create mode 100644 test/load wav.cpp (limited to 'test/load wav.cpp') diff --git a/test/load wav.cpp b/test/load wav.cpp new file mode 100644 index 0000000..4cd2756 --- /dev/null +++ b/test/load wav.cpp @@ -0,0 +1,65 @@ +#include "utils.h" +#if UNITTEST + +#include +#include +#include +#include "../audio/sdl/source.h" +#include "../audio/sdl/audio.h" + +using namespace jin::audio; +using namespace std; + +struct WAV +{ + int samples; + int channel, samplerate; + short* data; + int pos; +}; + +WAV wav; +static void callbackfunc(void *userdata, Uint8 *stream, int len) +{ + if (wav.pos > wav.samples) + wav.pos = 0; + int16_t* buffer = (int16_t*)stream; + int l = len / 2; + for (int i = 0; i < l; ++i) + { + buffer[i] = wav.data[wav.pos + i]; + } + wav.pos += l; +} +int length = 2226052; +char buf[2226052]; + +int main(int argc, char* argv[]) +{ + Audio* audio = SDLAudio::get(); + ifstream fs; + fs.open("a.wav", ios::binary); + fs.read(buf, length); + SDLAudioSetting setting; + SDL_AudioSpec spe; + setting.callback = callbackfunc; + wav_t wavconfig; + if (wav_read(&wavconfig, buf, length) != 0) + { + cout << "load wav failed\n"; + } + wav.channel = wavconfig.channels; + wav.data = (short*)wavconfig.data; + wav.pos = 0; + wav.samplerate = wavconfig.samplerate; + wav.samples = wavconfig.length; + audio->init(&setting); + while (true) + { + SDL_Delay(100); + } + audio->quit(); + return 0; +} + +#endif \ No newline at end of file -- cgit v1.1-26-g67d0