Exemple #1
0
static void *asap_play_thread(void *arg)
{
	while (thread_run) {
		static unsigned char buffer[BUFFERED_BLOCKS * (BITS_PER_SAMPLE / 8) * 2];
		int buffered_bytes;
		if (generated_eof) {
			xmms_usleep(10000);
			continue;
		}
		if (seek_to >= 0) {
			mod.output->flush(seek_to);
			ASAP_Seek(asap, seek_to);
			seek_to = -1;
		}
		buffered_bytes = BUFFERED_BLOCKS * channels * (BITS_PER_SAMPLE / 8);
		buffered_bytes = ASAP_Generate(asap, buffer, buffered_bytes,
			BITS_PER_SAMPLE == 8 ? ASAPSampleFormat_U8 : ASAPSampleFormat_S16_L_E);
		if (buffered_bytes == 0) {
			generated_eof = TRUE;
			mod.output->buffer_free();
			mod.output->buffer_free();
			continue;
		}
		mod.add_vis_pcm(mod.output->written_time(),
			BITS_PER_SAMPLE == 8 ? FMT_U8 : FMT_S16_LE,
			channels, buffered_bytes, buffer);
		while (thread_run && mod.output->buffer_free() < buffered_bytes)
			xmms_usleep(20000);
		if (thread_run)
			mod.output->write_audio(buffer, buffered_bytes);
	}
	pthread_exit(NULL);
}
Exemple #2
0
static QWORD WINAPI ASAP_SetPosition(void *inst, QWORD pos, DWORD mode)
{
	ASAPSTREAM *stream = (ASAPSTREAM *) inst;
	if ((BYTE) mode != BASS_POS_BYTE)
		errorn(BASS_ERROR_NOTAVAIL);
	ASAP_Seek(&stream->asap, bytes_to_duration(stream, pos));
	return pos;
}
int64_t Seek(void* context, int64_t time)
{
  if (!context)
    return 1;

  ASAPContext* ctx = (ASAPContext*)context;

  ASAP_Seek(ctx->asap, time);

  return time;
}
Exemple #4
0
static DWORD WINAPI playThread(LPVOID dummy)
{
	while (thread_run) {
		static
#if BITS_PER_SAMPLE == 8
			byte
#else
			short
#endif
			buffer[BUFFERED_BLOCKS * 2
#if SUPPORT_EQUALIZER
			* 2
#endif
			];
		int buffered_bytes = BUFFERED_BLOCKS * channels * (BITS_PER_SAMPLE / 8);
		if (seek_needed >= 0) {
			mod.outMod->Flush(seek_needed);
			ASAP_Seek(&asap, seek_needed);
			seek_needed = -1;
		}
		if (mod.outMod->CanWrite() >= buffered_bytes
#if SUPPORT_EQUALIZER
			<< mod.dsp_isactive()
#endif
		) {
			int t;
			buffered_bytes = ASAP_Generate(&asap, buffer, buffered_bytes, BITS_PER_SAMPLE);
			if (buffered_bytes <= 0) {
				mod.outMod->CanWrite();
				if (!mod.outMod->IsPlaying()) {
					PostMessage(mod.hMainWindow, WM_WA_MPEG_EOF, 0, 0);
					return 0;
				}
				Sleep(10);
				continue;
			}
			t = mod.outMod->GetWrittenTime();
			mod.SAAddPCMData(buffer, channels, BITS_PER_SAMPLE, t);
			mod.VSAAddPCMData(buffer, channels, BITS_PER_SAMPLE, t);
#if SUPPORT_EQUALIZER
			t = buffered_bytes / (channels * (BITS_PER_SAMPLE / 8));
			t = mod.dsp_dosamples((short *) buffer, t, BITS_PER_SAMPLE, channels, ASAP_SAMPLE_RATE);
			t *= channels * (BITS_PER_SAMPLE / 8);
			mod.outMod->Write((char *) buffer, t);
#else
			mod.outMod->Write((char *) buffer, buffered_bytes);
#endif
		}
		else
			Sleep(20);
	}
	return 0;
}
Exemple #5
0
	STDMETHODIMP SetPositions(LONGLONG *pCurrent, DWORD dwCurrentFlags, LONGLONG *pStop, DWORD dwStopFlags)
	{
		if ((dwCurrentFlags & AM_SEEKING_PositioningBitsMask) == AM_SEEKING_AbsolutePositioning)
		{
			CheckPointer(pCurrent, E_POINTER);
			int position = (int) (*pCurrent / (UNITS / MILLISECONDS));
			CAutoLock lck(&cs);
			ASAP_Seek(&asap, position);
			blocks = 0;
			if ((dwCurrentFlags & AM_SEEKING_ReturnTime) != 0)
				*pCurrent = position * (UNITS / MILLISECONDS);
			return S_OK;
		}
		return E_INVALIDARG;
	}
static void play_mseek(InputPlayback *playback,
#if _AUD_PLUGIN_VERSION >= 18
	int
#else
	gulong
#endif
	time)
{
	pthread_mutex_lock(&control_mutex);
	if (playing) {
		ASAP_Seek(asap, time);
#if _AUD_PLUGIN_VERSION >= 15
		playback->output->abort_write();
#endif
	}
	pthread_mutex_unlock(&control_mutex);
}
Exemple #7
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;    
}
Exemple #8
0
	int __cdecl SetPosition(int newPosition)
	{
		ASAP_Seek(&asap, newPosition);
		return newPosition;
	}
	void decode_seek(double p_seconds, abort_callback &p_abort)
	{
		ASAP_Seek(asap, (int) (p_seconds * 1000));
	}
Exemple #10
0
static long WINAPI asapSeekFile(long lTime)
{
	ASAP_Seek(&asap, (int) lTime);
	return lTime;
}
static int asap_seek(void *data, int sec)
{
	ASAP_Decoder *d = (ASAP_Decoder *) data;
	ASAP_Seek(d->asap, sec * 1000);
	return sec;
}
Exemple #12
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;
}