void decode_initialize(t_uint32 p_subsong, unsigned p_flags, abort_callback &p_abort) { int duration = get_song_duration(p_subsong, true); if (!ASAP_PlaySong(asap, p_subsong, duration)) throw exception_io_unsupported_format(); ASAP_MutePokeyChannels(asap, mute_mask); }
static void LoadAndPlay(int song) { byte module[ASAP_MODULE_MAX]; int module_len; int duration; if (!loadModule(current_filename, module, &module_len)) return; if (songs > 0) { ClearSongsMenu(); StopPlayback(); songs = 0; EnableMenuItem(hTrayMenu, IDM_SAVE_WAV, MF_BYCOMMAND | MF_GRAYED); } if (!DoLoad(&asap, module, module_len)) return; if (!WaveOut_Open(asap.module_info.channels)) { ShowError("Error initalizing WaveOut"); return; } if (song < 0) song = asap.module_info.default_song; songs = asap.module_info.songs; EnableMenuItem(hTrayMenu, IDM_SAVE_WAV, MF_BYCOMMAND | MF_ENABLED); updateInfoDialog(current_filename, song); SetSongsMenu(songs); CheckMenuRadioItem(hSongMenu, 0, songs - 1, song, MF_BYPOSITION); current_song = song; duration = asap.module_info.durations[song]; if (asap.module_info.loops[song]) duration = -1; ASAP_PlaySong(&asap, song, duration); Tray_Modify(hPlayIcon); WaveOut_Start(); }
static void asap_play_file(char *filename) { const ASAPInfo *info; int song; int duration; char *title; if (asap == NULL) return; if (!asap_load_file(filename)) return; if (!ASAP_Load(asap, filename, module, module_len)) return; info = ASAP_GetInfo(asap); song = ASAPInfo_GetDefaultSong(info); duration = ASAPInfo_GetDuration(info, song); if (!ASAP_PlaySong(asap, song, duration)) return; channels = ASAPInfo_GetChannels(info); if (!mod.output->open_audio(BITS_PER_SAMPLE == 8 ? FMT_U8 : FMT_S16_LE, ASAP_SAMPLE_RATE, channels)) return; title = asap_get_title(filename, info); mod.set_info(title, duration, BITS_PER_SAMPLE * 1000, ASAP_SAMPLE_RATE, channels); g_free(title); seek_to = -1; thread_run = TRUE; generated_eof = FALSE; pthread_create(&thread_handle, NULL, asap_play_thread, NULL); }
int playSong(int song) { int duration = getSongDurationInternal(ASAP_GetInfo(asap), song, asap); ASAP_PlaySong(asap, song, duration); /* FIXME: check errors */ ASAP_MutePokeyChannels(asap, mute_mask); return duration; }
static bool_t Load(asap* p) { format_reader* Reader = p->Format.Reader; char Path8[MAXPATH]; tchar_t Path[MAXPATH]; void* buf; int n = p->Format.FileSize; if (n<=0) n=65536; buf = malloc(n); if (!buf) return 0; Reader->Input->Get(Reader->Input,STREAM_URL,Path,sizeof(Path)); TcsToStr(Path8,sizeof(Path8),Path); n = Reader->Read(Reader,buf,n); n = ASAP_Load(Path8, buf, n); free(buf); if (!n) return 0; ASAP_PlaySong(ASAP_GetDefSong()); p->Samples = 0; return 1; }
static void PlaySong(HWND hWnd, unsigned int n) { CheckMenuRadioItem(hSongMenu, 0, songs - 1, n, MF_BYPOSITION); cursong = n; ASAP_PlaySong(n); Tray_Modify(hWnd, hPlayIcon); WaveOut_Start(); }
static void *asap_open(const char *uri) { ASAP_Decoder *d = (ASAP_Decoder *) xmalloc(sizeof(ASAP_Decoder)); if (!asap_load(d, uri) || !ASAP_PlaySong(d->asap, ASAPInfo_GetDefaultSong(ASAP_GetInfo(d->asap)), d->duration)) { asap_close(d); return NULL; } return d; }
void* Init(const char* strFile, unsigned int filecache, int* channels, int* samplerate, int* bitspersample, int64_t* totaltime, int* bitrate, AEDataFormat* format, const AEChannel** channelinfo) { int track=0; std::string toLoad(strFile); if (toLoad.find(".asapstream") != std::string::npos) { size_t iStart=toLoad.rfind('-') + 1; track = atoi(toLoad.substr(iStart, toLoad.size()-iStart-11).c_str()); // The directory we are in, is the file // that contains the bitstream to play, // so extract it size_t slash = toLoad.rfind('\\'); if (slash == std::string::npos) slash = toLoad.rfind('/'); toLoad = toLoad.substr(0, slash); } void* file = XBMC->OpenFile(toLoad.c_str(),0); if (!file) return NULL; int len = XBMC->GetFileLength(file); uint8_t* data = new uint8_t[len]; XBMC->ReadFile(file, data, len); XBMC->CloseFile(file); ASAPContext* result = new ASAPContext; result->asap = ASAP_New(); // Now load the module if (!ASAP_Load(result->asap, toLoad.c_str(), data, len)) { delete[] data; delete result; } delete[] data; const ASAPInfo* info = ASAP_GetInfo(result->asap); *channels = ASAPInfo_GetChannels(info); *samplerate = 44100; *bitspersample = 16; *totaltime = ASAPInfo_GetDuration(info, track); *format = AE_FMT_S16NE; *channelinfo = NULL; *bitrate = 0; ASAP_PlaySong(result->asap, track, *totaltime); return result; }
void decode_initialize(t_uint32 p_subsong, unsigned p_flags, abort_callback &p_abort) { int duration = module_info.durations[p_subsong]; if (duration < 0) { if (silence_seconds > 0) ASAP_DetectSilence(&asap, silence_seconds); duration = 1000 * song_length; } if (play_loops && module_info.loops[p_subsong]) duration = 1000 * song_length; ASAP_PlaySong(&asap, p_subsong, duration); ASAP_MutePokeyChannels(&asap, mute_mask); }
static void SaveWav(void) { byte module[ASAP_MODULE_MAX]; int module_len; ASAP_State asap; int duration; static OPENFILENAME ofn = { sizeof(OPENFILENAME), NULL, 0, "WAV files (*.wav)\0*.wav\0\0", NULL, 0, 0, wav_filename, MAX_PATH, NULL, 0, NULL, "Select output file", OFN_ENABLESIZING | OFN_EXPLORER | OFN_OVERWRITEPROMPT, 0, 0, "wav", 0, NULL, NULL }; if (!loadModule(current_filename, module, &module_len)) return; if (!DoLoad(&asap, module, module_len)) return; duration = asap.module_info.durations[current_song]; if (duration < 0) { if (MessageBox(hWnd, "This song has unknown duration.\n" "Use \"File information\" to update the source file with the correct duration.\n" "Do you want to save 3 minutes?", "Unknown duration", MB_YESNO | MB_ICONWARNING) != IDYES) return; duration = 180000; } ASAP_PlaySong(&asap, current_song, duration); strcpy(wav_filename, current_filename); ASAP_ChangeExt(wav_filename, "wav"); ofn.hwndOwner = hWnd; if (!GetSaveFileName(&ofn)) return; if (!DoSaveWav(&asap)) ShowError("Cannot save file"); }
static HSTREAM WINAPI StreamCreateProc(BASSFILE file, DWORD flags) { BOOL unicode = FALSE; const char *filename; char aFilename[MAX_PATH]; byte module[ASAP_MODULE_MAX]; int module_len; ASAPSTREAM *stream; int song; int duration; HSTREAM handle; filename = (const char *) bassfunc->file.GetFileName(file, &unicode); if (filename == NULL) error(BASS_ERROR_NOTFILE); if (unicode) { if (WideCharToMultiByte(CP_ACP, 0, (LPCWSTR) filename, -1, aFilename, MAX_PATH, NULL, NULL) <= 0) error(BASS_ERROR_NOTFILE); filename = aFilename; } module_len = bassfunc->file.Read(file, module, sizeof(module)); stream = malloc(sizeof(ASAPSTREAM)); if (stream == NULL) error(BASS_ERROR_MEM); if (!ASAP_Load(&stream->asap, filename, module, module_len)) { free(stream); error(BASS_ERROR_FILEFORM); } flags &= BASS_SAMPLE_SOFTWARE | BASS_SAMPLE_LOOP | BASS_SAMPLE_3D | BASS_SAMPLE_FX | BASS_STREAM_DECODE | BASS_STREAM_AUTOFREE | 0x3f000000; // 0x3f000000 = all speaker flags song = stream->asap.module_info.default_song; if ((flags & BASS_MUSIC_LOOP) != 0 && stream->asap.module_info.loops[song]) duration = -1; else duration = stream->asap.module_info.durations[song]; stream->duration = duration; ASAP_PlaySong(&stream->asap, song, duration); handle = bassfunc->CreateStream(ASAP_SAMPLE_RATE, stream->asap.module_info.channels, flags, &StreamProc, stream, &ASAPfuncs); if (handle == 0) { free(stream); return 0; // CreateStream set the error code } bassfunc->file.SetStream(file, handle); noerrorn(handle); }
static void process_file(const char *input_file) { FILE *fp; static unsigned char module[ASAPInfo_MAX_MODULE_LENGTH]; int module_len; ASAP *asap; const ASAPInfo *info; SDL_AudioSpec desired; fp = fopen(input_file, "rb"); if (fp == NULL) fatal_error("cannot open %s", input_file); module_len = fread(module, 1, sizeof(module), fp); fclose(fp); asap = ASAP_New(); if (!ASAP_Load(asap, input_file, module, module_len)) fatal_error("%s: unsupported file", input_file); info = ASAP_GetInfo(asap); if (song < 0) song = ASAPInfo_GetDefaultSong(info); if (!ASAP_PlaySong(asap, song, -1)) fatal_error("%s: PlaySong failed", input_file); print_header("Name", ASAPInfo_GetTitle(info)); print_header("Author", ASAPInfo_GetAuthor(info)); print_header("Date", ASAPInfo_GetDate(info)); if (SDL_Init(SDL_INIT_AUDIO) != 0) sdl_error("SDL_Init"); desired.freq = ASAP_SAMPLE_RATE; desired.format = AUDIO_S16LSB; desired.channels = ASAPInfo_GetChannels(info); desired.samples = 4096; desired.callback = audio_callback; desired.userdata = asap; if (SDL_OpenAudio(&desired, NULL) != 0) sdl_error("SDL_OpenAudio"); SDL_PauseAudio(0); printf(" playing - press Enter to quit\n"); getchar(); SDL_Quit(); }
BOOL Load(const char *filename) { HANDLE fh = CreateFile(filename, GENERIC_READ, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL | FILE_FLAG_SEQUENTIAL_SCAN, NULL); if (fh == INVALID_HANDLE_VALUE) return FALSE; byte module[ASAP_MODULE_MAX]; int module_len; BOOL ok = ReadFile(fh, module, ASAP_MODULE_MAX, (LPDWORD) &module_len, NULL); CloseHandle(fh); if (!ok) return FALSE; CAutoLock lck(&cs); loaded = ASAP_Load(&asap, filename, module, module_len); if (!loaded) return FALSE; int song = asap.module_info.default_song; duration = asap.module_info.durations[song]; ASAP_PlaySong(&asap, song, duration); blocks = 0; return TRUE; }
static void asap_play_file(char *filename) { int song; int duration; char *title; if (!asap_load_file(filename)) return; if (!ASAP_Load(&asap, filename, module, module_len)) return; song = asap.module_info.default_song; duration = asap.module_info.durations[song]; ASAP_PlaySong(&asap, song, duration); channels = asap.module_info.channels; if (!mod.output->open_audio(BITS_PER_SAMPLE == 8 ? FMT_U8 : FMT_S16_LE, ASAP_SAMPLE_RATE, channels)) return; title = asap_get_title(filename, &asap.module_info); mod.set_info(title, duration, BITS_PER_SAMPLE * 1000, ASAP_SAMPLE_RATE, channels); g_free(title); seek_to = -1; thread_run = TRUE; generated_eof = FALSE; pthread_create(&thread_handle, NULL, asap_play_thread, NULL); }
static void play_file(char *filename) { FILE *fp; static unsigned char module[65000]; unsigned int module_len; fp = fopen(filename, "rb"); if (fp == NULL) return; module_len = fread(module, 1, sizeof(module), fp); fclose(fp); if (!ASAP_Load(filename, module, module_len)) return; ASAP_PlaySong(ASAP_GetDefSong()); channels = ASAP_GetChannels(); buffered_bytes = BUFFERED_BLOCKS * channels * (BITS_PER_SAMPLE / 8); if (!mod.output->open_audio(BITS_PER_SAMPLE == 8 ? FMT_U8 : FMT_S16_NE, FREQUENCY, channels)) return; mod.set_info(NULL, -1, BITS_PER_SAMPLE * 1000, FREQUENCY, channels); thread_run = TRUE; pthread_create(&thread_handle, NULL, play_thread, NULL); }
/* this is the codec entry point */ enum codec_status codec_main(void) { int n_bytes; int song; int duration; char* module; int bytesPerSample =2; next_track: if (codec_init()) { DEBUGF("codec init failed\n"); return CODEC_ERROR; } while (!*ci->taginfo_ready && !ci->stop_codec) ci->sleep(1); codec_set_replaygain(ci->id3); int bytes_done =0; size_t filesize; ci->seek_buffer(0); module = ci->request_buffer(&filesize, ci->filesize); if (!module || (size_t)filesize < (size_t)ci->filesize) { DEBUGF("loading error\n"); return CODEC_ERROR; } /*Init ASAP */ if (!ASAP_Load(&asap, ci->id3->path, module, filesize)) { DEBUGF("%s: format not supported",ci->id3->path); return CODEC_ERROR; } /* Make use of 44.1khz */ ci->configure(DSP_SET_FREQUENCY, 44100); /* Sample depth is 16 bit little endian */ ci->configure(DSP_SET_SAMPLE_DEPTH, 16); /* Stereo or Mono output ? */ if(asap.module_info.channels ==1) { ci->configure(DSP_SET_STEREO_MODE, STEREO_MONO); bytesPerSample = 2; } else { ci->configure(DSP_SET_STEREO_MODE, STEREO_INTERLEAVED); bytesPerSample = 4; } /* reset eleapsed */ ci->set_elapsed(0); song = asap.module_info.default_song; duration = asap.module_info.durations[song]; if (duration < 0) duration = 180 * 1000; /* set id3 length, because metadata parse might not have done it */ ci->id3->length = duration; ASAP_PlaySong(&asap, song, duration); ASAP_MutePokeyChannels(&asap, 0); /* The main decoder loop */ while (1) { ci->yield(); if (ci->stop_codec || ci->new_track) break; if (ci->seek_time) { /* New time is ready in ci->seek_time */ /* seek to pos */ ASAP_Seek(&asap,ci->seek_time); /* update elapsed */ ci->set_elapsed(ci->seek_time); /* update bytes_done */ bytes_done = ci->seek_time*44.1*2; /* seek ready */ ci->seek_complete(); } /* Generate a buffer full of Audio */ #ifdef ROCKBOX_LITTLE_ENDIAN n_bytes = ASAP_Generate(&asap, samples, sizeof(samples), ASAP_FORMAT_S16_LE); #else n_bytes = ASAP_Generate(&asap, samples, sizeof(samples), ASAP_FORMAT_S16_BE); #endif ci->pcmbuf_insert(samples, NULL, n_bytes /bytesPerSample); bytes_done += n_bytes; ci->set_elapsed((bytes_done / 2) / 44.1); if(n_bytes != sizeof(samples)) break; } if (ci->request_next_track()) goto next_track; return CODEC_OK; }
cibool EMSCRIPTEN_KEEPALIVE asap_playSong(int song, int duration, int boostVolume) { setBoostVolume(boostVolume & 0xff); return ASAP_PlaySong(getAsap(), song, duration); }
static gboolean play_start(InputPlayback *playback, const char *filename, VFSFile *file, int start_time, int stop_time, gboolean pause) { int song = -1; unsigned char module[ASAPInfo_MAX_MODULE_LENGTH]; int module_len; gboolean ok; const ASAPInfo *info; int channels; #if _AUD_PLUGIN_VERSION >= 10 char *real_filename = filename_split_subtune(filename, &song); if (real_filename != NULL) filename = real_filename; #endif module_len = load_module(filename, file, module); ok = module_len > 0 && ASAP_Load(asap, filename, module, module_len); #if _AUD_PLUGIN_VERSION >= 10 g_free(real_filename); #endif if (!ok) return FALSE; info = ASAP_GetInfo(asap); channels = ASAPInfo_GetChannels(info); if (song > 0) song--; else song = ASAPInfo_GetDefaultSong(info); if (stop_time < 0) stop_time = ASAPInfo_GetDuration(info, song); if (!ASAP_PlaySong(asap, song, stop_time)) return FALSE; if (start_time > 0) ASAP_Seek(asap, start_time); if (!playback->output->open_audio(BITS_PER_SAMPLE == 8 ? FMT_U8 : FMT_S16_LE, ASAP_SAMPLE_RATE, channels)) return FALSE; playback->set_params(playback, #if _AUD_PLUGIN_VERSION < 18 NULL, 0, #endif 0, ASAP_SAMPLE_RATE, channels); if (pause) playback->output->pause(TRUE); playing = TRUE; playback->set_pb_ready(playback); for (;;) { static unsigned char buffer[4096]; int len; pthread_mutex_lock(&control_mutex); if (!playing) { pthread_mutex_unlock(&control_mutex); break; } len = ASAP_Generate(asap, buffer, sizeof(buffer), BITS_PER_SAMPLE == 8 ? ASAPSampleFormat_U8 : ASAPSampleFormat_S16_L_E); pthread_mutex_unlock(&control_mutex); if (len <= 0) { #if _AUD_PLUGIN_VERSION < 18 playback->eof = TRUE; #endif break; } #if _AUD_PLUGIN_VERSION >= 14 playback->output->write_audio(buffer, len); #else playback->pass_audio(playback, BITS_PER_SAMPLE == 8 ? FMT_U8 : FMT_S16_LE, channels, len, buffer, NULL); #endif } #if _AUD_PLUGIN_VERSION_MIN < 40 while (playing && playback->output->buffer_playing()) g_usleep(10000); #endif pthread_mutex_lock(&control_mutex); playing = FALSE; pthread_mutex_unlock(&control_mutex); #if _AUD_PLUGIN_VERSION_MIN < 40 playback->output->close_audio(); #endif return TRUE; }