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); }
static Tuple *probe_for_tuple(const char *filename, VFSFile *file) { int song = -1; unsigned char module[ASAPInfo_MAX_MODULE_LENGTH]; int module_len; ASAPInfo *info = NULL; Tuple *tuple = NULL; int songs; int duration; int year; #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); if (module_len > 0) { info = ASAPInfo_New(); if (info != NULL && ASAPInfo_Load(info, filename, module, module_len)) tuple = tuple_new_from_filename(filename); } #if _AUD_PLUGIN_VERSION >= 10 g_free(real_filename); #endif if (tuple == NULL) { ASAPInfo_Delete(info); return NULL; } tuple_set_nonblank(tuple, FIELD_ARTIST, ASAPInfo_GetAuthor(info)); tuple_set_nonblank(tuple, FIELD_TITLE, ASAPInfo_GetTitleOrFilename(info)); tuple_set_nonblank(tuple, FIELD_DATE, ASAPInfo_GetDate(info)); tuple_set_str(tuple, FIELD_CODEC, NULL, "ASAP"); songs = ASAPInfo_GetSongs(info); if (song > 0) { tuple_set_int(tuple, FIELD_SUBSONG_ID, NULL, song); tuple_set_int(tuple, FIELD_SUBSONG_NUM, NULL, songs); song--; } else { if (songs > 1) { #if _AUD_PLUGIN_VERSION >= 37 tuple_set_subtunes(tuple, songs, NULL); #else tuple->nsubtunes = songs; #endif } song = ASAPInfo_GetDefaultSong(info); } duration = ASAPInfo_GetDuration(info, song); if (duration > 0) tuple_set_int(tuple, FIELD_LENGTH, NULL, duration); year = ASAPInfo_GetYear(info); if (year > 0) tuple_set_int(tuple, FIELD_YEAR, NULL, year); ASAPInfo_Delete(info); return tuple; }
static void asap_get_song_info(char *filename, char **title, int *length) { ASAPInfo *info = asap_get_info(filename); if (info == NULL) return; *title = asap_get_title(filename, info); *length = ASAPInfo_GetDuration(info, ASAPInfo_GetDefaultSong(info)); ASAPInfo_Delete(info); }
static void setSaved(void) { int i; _tcscpy(saved_author, ASAPInfo_GetAuthor(edited_info)); _tcscpy(saved_title, ASAPInfo_GetTitle(edited_info)); _tcscpy(saved_date, ASAPInfo_GetDate(edited_info)); for (i = 0; i < ASAPInfo_GetSongs(edited_info); i++) { saved_durations[i] = ASAPInfo_GetDuration(edited_info, i); saved_loops[i] = ASAPInfo_GetLoop(edited_info, i); } }
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; }
static BOOL saveFile(LPCTSTR filename, BOOL tag) { BOOL isSap = isExt(filename, _T(".sap")); if (isSap) { int song = ASAPInfo_GetSongs(edited_info); while (--song >= 0 && ASAPInfo_GetDuration(edited_info, song) < 0); while (--song >= 0) { if (ASAPInfo_GetDuration(edited_info, song) < 0) { MessageBox(infoDialog, _T("Cannot save file because time not set for all songs"), _T("Error"), MB_OK | MB_ICONERROR); return FALSE; } } } if (!doSaveFile(filename, tag)) { MessageBox(infoDialog, _T("Cannot save file"), _T("Error"), MB_OK | MB_ICONERROR); // FIXME: delete file return FALSE; } if (isSap) setSaved(); return TRUE; }
int getSongDurationInternal(const ASAPInfo *info, int song, ASAP *asap) { int duration = ASAPInfo_GetDuration(info, song); if (duration < 0) { if (asap != NULL) ASAP_DetectSilence(asap, silence_seconds); return 1000 * song_length; } if (asap != NULL) ASAP_DetectSilence(asap, 0); if (play_loops && ASAPInfo_GetLoop(info, song)) return 1000 * song_length; return duration; }
int get_song_duration(int song, bool play) { const ASAPInfo *info = ASAP_GetInfo(asap); int duration = ASAPInfo_GetDuration(info, song); if (duration < 0) { if (play) ASAP_DetectSilence(asap, silence_seconds); return 1000 * song_length; } if (play) ASAP_DetectSilence(asap, 0); if (play_loops && ASAPInfo_GetLoop(info, song)) return 1000 * song_length; return duration; }
static BOOL infoChanged(void) { int i; if (_tcscmp(ASAPInfo_GetAuthor(edited_info), saved_author) != 0) return TRUE; if (_tcscmp(ASAPInfo_GetTitle(edited_info), saved_title) != 0) return TRUE; if (_tcscmp(ASAPInfo_GetDate(edited_info), saved_date) != 0) return TRUE; for (i = 0; i < ASAPInfo_GetSongs(edited_info); i++) { if (ASAPInfo_GetDuration(edited_info, i) != saved_durations[i]) return TRUE; if (saved_durations[i] >= 0 && ASAPInfo_GetLoop(edited_info, i) != saved_loops[i]) return TRUE; } return FALSE; }
static void setEditedSong(int song) { _TCHAR filename[MAX_PATH]; unsigned char str[ASAPWriter_MAX_DURATION_LENGTH + 1]; int len; edited_song = song; len = ASAPWriter_DurationToString(str, ASAPInfo_GetDuration(edited_info, song)); str[len] = '\0'; SendDlgItemMessage(infoDialog, IDC_TIME, WM_SETTEXT, 0, (LPARAM) str); CheckDlgButton(infoDialog, IDC_LOOP, ASAPInfo_GetLoop(edited_info, song) ? BST_CHECKED : BST_UNCHECKED); EnableWindow(GetDlgItem(infoDialog, IDC_LOOP), len > 0); SendDlgItemMessage(infoDialog, IDC_FILENAME, WM_GETTEXT, MAX_PATH, (LPARAM) filename); ASTIL_Load(astil, filename, song); SendDlgItemMessage(infoDialog, IDC_STILFILE, WM_SETTEXT, 0, (LPARAM) ASTIL_GetStilFilename(astil)); updateStil(); }
bool ReadTag(const char* strFile, char* title, char* artist, int* length) { int track=1; 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 false; int len = XBMC->GetFileLength(file); uint8_t* data = new uint8_t[len]; XBMC->ReadFile(file, data, len); XBMC->CloseFile(file); ASAP* asap = ASAP_New(); // Now load the module if (!ASAP_Load(asap, strFile, data, len)) { delete[] data; return false; } delete[] data; const ASAPInfo* info = ASAP_GetInfo(asap); strcpy(artist, ASAPInfo_GetAuthor(info)); strcpy(title, ASAPInfo_GetTitleOrFilename(info)); *length = ASAPInfo_GetDuration(info, track); return true; }
static cibool asap_load(ASAP_Decoder *d, const char *filename) { struct io_stream *s; ssize_t module_len; unsigned char *module; cibool ok; const ASAPInfo *info; int song; int duration; d->asap = NULL; decoder_error_init(&d->error); s = io_open(filename, 0); if (s == NULL) { decoder_error(&d->error, ERROR_FATAL, 0, "Can't open %s", filename); return FALSE; } module_len = io_file_size(s); module = (unsigned char *) xmalloc(module_len); module_len = io_read(s, module, module_len); io_close(s); d->asap = ASAP_New(); if (d->asap == NULL) { decoder_error(&d->error, ERROR_FATAL, 0, "Out of memory"); return FALSE; } ok = ASAP_Load(d->asap, filename, module, module_len); free(module); if (!ok) { decoder_error(&d->error, ERROR_FATAL, 0, "Unsupported file format"); return FALSE; } info = ASAP_GetInfo(d->asap); song = ASAPInfo_GetDefaultSong(info); duration = ASAPInfo_GetDuration(info, song); if (duration < 0) duration = DEFAULT_SONG_LENGTH * 1000; d->duration = duration; return TRUE; }
int EMSCRIPTEN_KEEPALIVE asapinfo_GetDuration(int song) { return ASAPInfo_GetDuration(info, song); }
HRESULT GetData(LPCSHCOLUMNID pscid, PROPVARIANT *pvarData, BOOL vista) { if (!m_hasInfo) return S_FALSE; if (pscid->fmtid == FMTID_SummaryInformation) { if (pscid->pid == PIDSI_TITLE) return GetString(pvarData, ASAPInfo_GetTitle(m_pinfo)); if (pscid->pid == PIDSI_AUTHOR) return GetAuthors(pvarData, vista); } else if (pscid->fmtid == FMTID_MUSIC) { if (pscid->pid == PIDSI_ARTIST) return GetAuthors(pvarData, vista); if (pscid->pid == PIDSI_YEAR) { int year = ASAPInfo_GetYear(m_pinfo); if (year < 0) { pvarData->vt = VT_EMPTY; return S_OK; } pvarData->vt = VT_UI8; pvarData->ulVal = (ULONG) year; return S_OK; } } else if (pscid->fmtid == FMTID_AudioSummaryInformation) { if (pscid->pid == PIDASI_TIMELENGTH) { int duration = ASAPInfo_GetDuration(m_pinfo, ASAPInfo_GetDefaultSong(m_pinfo)); if (duration < 0) { pvarData->vt = VT_EMPTY; return S_OK; } if (g_windowsVer == WINDOWS_OLD) { duration /= 1000; char timeStr[16]; sprintf(timeStr, "%02d:%02d:%02d", duration / 3600, duration / 60 % 60, duration % 60); return GetString(pvarData, timeStr); } else { pvarData->vt = VT_UI8; pvarData->uhVal.QuadPart = 10000ULL * duration; return S_OK; } } if (pscid->pid == PIDASI_CHANNEL_COUNT) { pvarData->vt = VT_UI4; pvarData->ulVal = (ULONG) ASAPInfo_GetChannels(m_pinfo); return S_OK; } } else if (pscid->fmtid == CLSID_ASAPMetadataHandler) { if (pscid->pid == 1) { pvarData->vt = VT_UI4; pvarData->ulVal = (ULONG) ASAPInfo_GetSongs(m_pinfo); return S_OK; } if (pscid->pid == 2) return GetString(pvarData, ASAPInfo_IsNtsc(m_pinfo) ? "NTSC" : "PAL"); } return S_FALSE; }
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; }