- #include <stdio.h>
- #include <stdint.h>
- #include <string.h>
- #include <SDL2/SDL.h>
- #include <acm/libacm.h>
-
-
-
-
-
-
-
-
-
-
-
- static uint8_t *audio_pos;
- static uint32_t audio_len;
-
-
-
-
-
-
- void my_audio_callback(void * userdata, Uint8 *stream, int len) {
- if (audio_len ==0)
- return;
- len = ( (unsigned)len > audio_len ? audio_len : (unsigned)len );
- SDL_MixAudio(stream, audio_pos, len, SDL_MIX_MAXVOLUME);
-
- audio_pos += len;
- audio_len -= len;
- }
-
-
-
-
- uint8_t DetectFakeStereo(const char *fn) {
- uint8_t result = 0;
- char * pointer;
- pointer = strstr(fn,"Speech");
- if(pointer != NULL) {
- result = 1;
- }
- return result;
- }
-
- int main(int argc, char* argv[]){
- static uint32_t wav_length;
- static uint8_t *wav_buffer;
- static SDL_AudioSpec wav_spec;
- uint32_t wavsize;
- char * fn2 = NULL;
- uint8_t cf_force_chans;
- SDL_RWops * WavFromACM = NULL;
- if ( argc != 2 ) {
- fputs("Need a path to ACM file\n",stderr);
- return 2;
- }
- if (SDL_Init(SDL_INIT_AUDIO) < 0) {
- fputs("Could not SDL_Init\n",stderr);
- return 1;
- }
-
- cf_force_chans = DetectFakeStereo(argv[1]);
-
- cf_force_chans = 1;
-
- fn2 = libacm_decode_file_to_mem(argv[1],cf_force_chans,&wavsize);
-
- WavFromACM = SDL_RWFromConstMem(fn2,wavsize);
- if(SDL_LoadWAV_RW(WavFromACM,1,&wav_spec,&wav_buffer, &wav_length) == NULL) {
- free(fn2);
- fputs("Loading the ACM didn't succeed\n",stderr);
- return 2;
- }
-
- wav_spec.callback = my_audio_callback;
- wav_spec.userdata = NULL;
-
- audio_pos = wav_buffer;
- audio_len = wav_length;
-
- if ( SDL_OpenAudio(&wav_spec, NULL) < 0 ){
- fprintf(stderr, "Couldn't open audio: %s\n", SDL_GetError());
- free(fn2);
- exit(-1);
- }
-
- SDL_PauseAudio(0);
-
- while ( audio_len > 0 ) {
- SDL_Delay(100);
- }
-
- SDL_CloseAudio();
- SDL_FreeWAV(wav_buffer);
- free(fn2);
- return 0;
- }
You must be logged in to paste new items to the PasteBin