bool decode_run( audio_chunk & p_chunk, abort_callback & p_abort ) { if (!loop && m_info.musicTimeInMs == ymMusicGetPos(m_player)) return false; int nbSample = 500 / sizeof(ymsample); sample_buffer.grow_size( nbSample ); ymMusicCompute(m_player,sample_buffer.get_ptr(), nbSample); p_chunk.set_data_fixedpoint( sample_buffer.get_ptr(), nbSample * 2, 44100, 1, 16, audio_chunk::channel_config_mono ); return true; }
DWORD YMPlugin::GetCurPos(DWORD subsong) { return ymMusicGetPos(m_ymMusic); }
int main(int argc, char* argv[]) { //-------------------------------------------------------------------------- // Checks args. //-------------------------------------------------------------------------- printf( "SmallYmPlayer.\n" "Using ST-Sound Library, under GPL license\n" "Copyright (C) 1995-1999 Arnaud Carre ( http://leonard.oxg.free.fr )\n"); if (argc!=2) { printf("Usage: SmallYmPlayer <ym music file>\n\n"); return -1; } //-------------------------------------------------------------------------- // Load YM music and creates WAV file //-------------------------------------------------------------------------- printf("Loading music \"%s\"...\n",argv[1]); YMMUSIC *pMusic = ymMusicCreate(); if (ymMusicLoad(pMusic,argv[1])) { if (soundServer.open(soundServerCallback,500)) { ymMusicInfo_t info; ymMusicGetInfo(pMusic,&info); printf("Name.....: %s\n",info.pSongName); printf("Author...: %s\n",info.pSongAuthor); printf("Comment..: %s\n",info.pSongComment); printf("Duration.: %d:%02d\n",info.musicTimeInSec/60,info.musicTimeInSec%60); printf("\nPlaying music...(press a key to abort)\n"); ymMusicSetLoopMode(pMusic,YMTRUE); ymMusicPlay(pMusic); s_pMusic = pMusic; // global instance for soundserver callback int oldSec = -1; for (;;) { if (_kbhit()) break; int sec = ymMusicGetPos(pMusic) / 1000; if (sec != oldSec) { printf("Time: %d:%02d\r",sec/60,sec%60); oldSec = sec; } Sleep(20); } _getch(); // flush the key pressed printf("\n"); // Switch off replayer s_pMusic = NULL; ymMusicStop(pMusic); soundServer.close(); } else { printf("ERROR: Unable to initialize sound card hardware\n"); } } else { printf("Error in loading file %s:\n%s\n",argv[1],ymMusicGetLastError(pMusic)); } ymMusicDestroy(pMusic); return 0; }