Ejemplo n.º 1
0
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);
}
Ejemplo n.º 2
0
cibool EMSCRIPTEN_KEEPALIVE asap_load(const char *filename, unsigned char *buf, long len) {
	if (asap != 0) {
		ASAP_Delete(asap);
		asap= 0;
	}
	return ASAP_Load(getAsap(), filename, buf, len);
}
Ejemplo n.º 3
0
static int play(char *fn)
{
	int song;
	int maxlatency;
	DWORD threadId;
	strcpy(current_filename_with_song, fn);
	song = extractSongNumber(fn, current_filename);
	if (!loadModule(current_filename, module, &module_len))
		return -1;
	if (!ASAP_Load(&asap, current_filename, module, module_len))
		return 1;
	if (song < 0)
		song = asap.module_info.default_song;
	duration = playSong(song);
	maxlatency = mod.outMod->Open(ASAP_SAMPLE_RATE, channels, BITS_PER_SAMPLE, -1, -1);
	if (maxlatency < 0)
		return 1;
	mod.SetInfo(BITS_PER_SAMPLE, ASAP_SAMPLE_RATE / 1000, channels, 1);
	mod.SAVSAInit(maxlatency, ASAP_SAMPLE_RATE);
	// the order of VSASetInfo's arguments in in2.h is wrong!
	// http://forums.winamp.com/showthread.php?postid=1841035
	mod.VSASetInfo(ASAP_SAMPLE_RATE, channels);
	mod.outMod->SetVolume(-666);
	seek_needed = -1;
	thread_run = TRUE;
	thread_handle = CreateThread(NULL, 0, playThread, NULL, 0, &threadId);
	if (playing_info)
		updateInfoDialog(current_filename, song);
	return thread_handle != NULL ? 0 : 1;
}
Ejemplo n.º 4
0
static int play(char *fn)
{
	char filename[MAX_PATH];
	int song;
	const ASAPInfo *info;
	int channels;
	int maxlatency;
	DWORD threadId;
	strcpy(playing_filename_with_song, fn);
	song = extractSongNumber(fn, filename);
	if (!loadModule(filename, module, &module_len))
		return -1;
	if (!ASAP_Load(asap, filename, module, module_len))
		return 1;
	info = ASAP_GetInfo(asap);
	if (song < 0)
		song = ASAPInfo_GetDefaultSong(info);
	duration = playSong(song);
	channels = ASAPInfo_GetChannels(info);
	maxlatency = mod.outMod->Open(ASAP_SAMPLE_RATE, channels, BITS_PER_SAMPLE, -1, -1);
	if (maxlatency < 0)
		return 1;
	mod.SetInfo(BITS_PER_SAMPLE, ASAP_SAMPLE_RATE / 1000, channels, 1);
	mod.SAVSAInit(maxlatency, ASAP_SAMPLE_RATE);
	// the order of VSASetInfo's arguments in in2.h is wrong!
	// http://forums.winamp.com/showthread.php?postid=1841035
	mod.VSASetInfo(ASAP_SAMPLE_RATE, channels);
	mod.outMod->SetVolume(-666);
	seek_needed = -1;
	thread_run = TRUE;
	thread_handle = CreateThread(NULL, 0, playThread, NULL, 0, &threadId);
	setPlayingSong(filename, song);
	return thread_handle != NULL ? 0 : 1;
}
Ejemplo n.º 5
0
static void LoadFile(HWND hWnd)
{
	HANDLE fh;
	static unsigned char module[65000];
	DWORD module_len;
	fh = CreateFile(strFile, GENERIC_READ, 0, NULL, OPEN_EXISTING,
	                FILE_ATTRIBUTE_NORMAL | FILE_FLAG_SEQUENTIAL_SCAN, NULL);
	if (fh == INVALID_HANDLE_VALUE)
		return;
	if (!ReadFile(fh, module, sizeof(module), &module_len, NULL)) {
		CloseHandle(fh);
		return;
	}
	CloseHandle(fh);
	WaveOut_Close();
	if (ASAP_Load(strFile, module, (unsigned int) module_len)) {
		if (!WaveOut_Open(FREQUENCY, use_16bit, ASAP_GetChannels())) {
			SetSongs(0);
			Tray_Modify(hWnd, hStopIcon);
			MessageBox(hWnd, "Error initalizing WaveOut", APP_TITLE,
					   MB_OK | MB_ICONERROR);
			return;
		}
		SetSongs(ASAP_GetSongs());
		PlaySong(hWnd, ASAP_GetDefSong());
	}
	else {
		SetSongs(0);
		Tray_Modify(hWnd, hStopIcon);
		MessageBox(hWnd, "Unsupported file format", APP_TITLE,
		           MB_OK | MB_ICONERROR);
	}
}
Ejemplo n.º 6
0
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;
}
Ejemplo n.º 7
0
int TrackCount(const char* strFile)
{
  void* file = XBMC->OpenFile(strFile, 0);
  if (!file)
    return 1;

  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))
  {
    ASAP_Delete(asap);
    delete[] data;
    return 1;
  }
  delete[] data;

  const ASAPInfo* info = ASAP_GetInfo(asap);
  int result = ASAPInfo_GetSongs(info);
  ASAP_Delete(asap);

  return result;
}
Ejemplo n.º 8
0
Archivo: wasap.c Proyecto: 070499/xbmc
static BOOL DoLoad(ASAP_State *asap, byte module[], int module_len)
{
	if (!ASAP_Load(asap, current_filename, module, module_len)) {
		ShowError("Unsupported file format");
		return FALSE;
	}
	return TRUE;
}
Ejemplo n.º 9
0
	CInputDecoder * __cdecl Open(char *filename, int audioDataOffset)
	{
		byte module[ASAP_MODULE_MAX];
		int module_len;
		if (!loadModule(filename, module, &module_len))
			return NULL;
		if (!ASAP_Load(&asap, filename, module, module_len))
			return NULL;
		playSong(asap.module_info.default_song);
		return new CASAPDecoder();
	}
Ejemplo n.º 10
0
	CInputDecoder * __cdecl Open(char *filename, int audioDataOffset)
	{
		BYTE module[ASAPInfo_MAX_MODULE_LENGTH];
		int module_len;
		if (!loadModule(filename, module, &module_len))
			return NULL;
		if (!ASAP_Load(asap, filename, module, module_len))
			return NULL;
		playSong(ASAPInfo_GetDefaultSong(ASAP_GetInfo(asap)));
		return new CASAPDecoder();
	}
Ejemplo n.º 11
0
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;
}
Ejemplo n.º 12
0
static BOOL WINAPI asapOpenFile(LPCTSTR pszFile, MAP_PLUGIN_FILE_INFO *pInfo)
{
	CONVERT_FILENAME;
	if (!loadFile(pszFile))
		return FALSE;
	if (!ASAP_Load(&asap, ANSI_FILENAME, module, module_len))
		return FALSE;
	pInfo->nChannels = asap.module_info.channels;
	pInfo->nSampleRate = ASAP_SAMPLE_RATE;
	pInfo->nBitsPerSample = BITS_PER_SAMPLE;
	pInfo->nAvgBitrate = 8;
	pInfo->nDuration = getSongDuration(&asap.module_info, asap.module_info.default_song);
	return TRUE;
}
Ejemplo n.º 13
0
	void open(service_ptr_t<file> p_filehint, const char *p_path, t_input_open_reason p_reason, abort_callback &p_abort)
	{
		if (p_reason == input_open_info_write) {
			int len = strlen(p_path);
			if (len < 4 || _stricmp(p_path + len - 4, ".sap") != 0)
				throw exception_io_unsupported_format();
			filename = strdup(p_path);
		}
		if (p_filehint.is_empty())
			filesystem::g_open(p_filehint, p_path, filesystem::open_mode_read, p_abort);
		m_file = p_filehint;
		module_len = m_file->read(module, sizeof(module), p_abort);
		if (!ASAP_Load(asap, p_path, module, module_len))
			throw exception_io_unsupported_format();
	}
Ejemplo n.º 14
0
	void open(service_ptr_t<file> p_filehint, const char *p_path, t_input_open_reason p_reason, abort_callback &p_abort)
	{
		if (p_reason == input_open_info_write) {
			int len = strlen(p_path);
			if (len >= MAX_PATH || !ASAP_CanSetModuleInfo(p_path))
				throw exception_io_unsupported_format();
			memcpy(filename, p_path, len + 1);
		}
		if (p_filehint.is_empty())
			filesystem::g_open(p_filehint, p_path, filesystem::open_mode_read, p_abort);
		m_file = p_filehint;
		module_len = m_file->read(module, sizeof(module), p_abort);
		if (!ASAP_GetModuleInfo(&module_info, p_path, module, module_len))
			throw exception_io_unsupported_format();
		if (p_reason == input_open_decode)
			if (!ASAP_Load(&asap, p_path, module, module_len))
				throw exception_io_unsupported_format();
	}
Ejemplo n.º 15
0
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);
}
Ejemplo n.º 16
0
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;
}
Ejemplo n.º 17
0
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;
}
Ejemplo n.º 18
0
Archivo: asap-sdl.c Proyecto: epi/asap
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();
}
Ejemplo n.º 19
0
	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;
	}
Ejemplo n.º 20
0
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);
}
Ejemplo n.º 21
0
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);
}
Ejemplo n.º 22
0
/* 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;    
}
Ejemplo n.º 23
0
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;
}