Exemplo n.º 1
0
/**
**  Type member function to read from the module
**
**  @param buf     Buffer to write data to
**  @param len     Length of the buffer
**
**  @return        Number of bytes read
*/
int CSampleMikModStream::Read(void *buf, int len)
{
	int read;

	// fill up the buffer
	read = 0;
	while (this->Len < SOUND_BUFFER_SIZE / 2 && Player_Active()) {
		memcpy(this->Buffer, this->Buffer + this->Pos, this->Len);
		this->Pos = 0;
		CurrentFile = this->Data.MikModFile;
		read = VC_WriteBytes((SBYTE *)this->Buffer + this->Pos,
			SOUND_BUFFER_SIZE - (this->Pos + this->Len));
		this->Len += read;
	}

	if (this->Len < len) {
		// EOF
		len = this->Len;
	}

	memcpy(buf, this->Buffer + this->Pos, len);
	this->Len -= len;
	this->Pos += len;

	return len;
}
Exemplo n.º 2
0
Arquivo: drv_nos.c Projeto: jjgod/SDL
static void NS_Update(void)
{
#ifndef SDL_MIXER_ONLY
	if (zerobuf)
		VC_WriteBytes(zerobuf,ZEROLEN);
#endif
}
Exemplo n.º 3
0
static void DS_Update(void)
{
	LPVOID block;
	DWORD bBytes;

	/* Do first update in DS_Update() to be consistent with other
	   non threaded drivers. */
	if (do_update && pSoundBuffer) {
		do_update = 0;

		if (pSoundBuffer->lpVtbl->Lock (pSoundBuffer, 0, fragsize,
										&block, &bBytes, NULL, NULL, 0)
				== DSERR_BUFFERLOST) {
			pSoundBuffer->lpVtbl->Restore (pSoundBuffer);
			pSoundBuffer->lpVtbl->Lock (pSoundBuffer, 0, fragsize,
										&block, &bBytes, NULL, NULL, 0);
		}

		if (Player_Paused_internal()) {
			VC_SilenceBytes ((SBYTE *)block, (ULONG)bBytes);
		} else {
			VC_WriteBytes ((SBYTE *)block, (ULONG)bBytes);
		}

		pSoundBuffer->lpVtbl->Unlock (pSoundBuffer, block, bBytes, NULL, 0);

		pSoundBuffer->lpVtbl->SetCurrentPosition(pSoundBuffer, 0);
		pSoundBuffer->lpVtbl->Play(pSoundBuffer, 0, 0, DSBPLAY_LOOPING);

		threadInUse=1;
		ResumeThread (updateBufferHandle);
	}
}
Exemplo n.º 4
0
static void ALSA_Update(void)
{
    int err;

    {
        if (bytes_written == 0 || bytes_played == bytes_written)
        {
            bytes_written = VC_WriteBytes(audiobuffer,buffer_size_in_frames * global_frame_size);
            bytes_played = 0;
        }

        while (bytes_played < bytes_written)
        {
            err = alsa_pcm_writei(pcm_h, &audiobuffer[bytes_played], (bytes_written - bytes_played) / global_frame_size);
            if (err == -EAGAIN)
            {
                continue;
            }
            if (err < 0) {
                if ((err = xrun_recovery(pcm_h, err)) < 0) {
                    printf("Write error: %s\n", alsa_strerror(err));
                    exit(-1);
                }
                break;
            }
            bytes_played += err * global_frame_size;
        }
    }
}
Exemplo n.º 5
0
static void ALSA_Update(void)
{
	int err;

	if (!enabled) return;

	if (bytes_written == 0 || bytes_played == bytes_written) {
		bytes_written = VC_WriteBytes(audiobuffer,period_size * global_frame_size);
		bytes_played = 0;
	}

	while (bytes_played < bytes_written)
	{
		err = alsa_pcm_writei(pcm_h, &audiobuffer[bytes_played], (bytes_written - bytes_played) / global_frame_size);
		if (err == -EAGAIN)
			continue;
		if (err < 0) {
			if ((err = xrun_recovery(pcm_h, err)) < 0) {
				_mm_errno = MMERR_ALSA_PCM_RECOVER;
				enabled = 0;
				dbgprint(stderr, "Write error: %s\n", alsa_strerror(err));
			}
			break;
		}
		bytes_played += err * global_frame_size;
	}
}
Exemplo n.º 6
0
static DWORD WINAPI UpdateBufferProc(LPVOID lpParameter) {
	while (threadInUse) {
		while (1) {
			XAUDIO2_VOICE_STATE state;
			XAUDIO2_BUFFER audio_buf;

			#if !defined(DRV_XAUDIO28)
			IXAudio2SourceVoice_GetState(pSourceVoice, &state);
			#else
			IXAudio2SourceVoice_GetState(pSourceVoice, &state, XAUDIO2_VOICE_NOSAMPLESPLAYED);
			#endif
			if (state.BuffersQueued >= XAUDIO2_NUM_BUFFERS - 1)
				break;
			MUTEX_LOCK(vars);
			if (Player_Paused_internal())
				VC_SilenceBytes((SBYTE *) buffers[current_buf], (ULONG) XAUDIO2_BUFFER_SIZE);
			else
				VC_WriteBytes((SBYTE *) buffers[current_buf], (ULONG) XAUDIO2_BUFFER_SIZE);
			MUTEX_UNLOCK(vars);
			memset(&audio_buf, 0, sizeof(XAUDIO2_BUFFER));
			audio_buf.AudioBytes = XAUDIO2_BUFFER_SIZE;
			audio_buf.pAudioData = buffers[current_buf];
			IXAudio2SourceVoice_SubmitSourceBuffer(pSourceVoice, &audio_buf, NULL);
			current_buf++;
			current_buf %= XAUDIO2_NUM_BUFFERS;
		}
		WaitForSingleObject(hBufferEvent, INFINITE);
	}
	return 0;
}
Exemplo n.º 7
0
static void XAudio2_Update(void) {
	if (do_update && pSourceVoice) {
		do_update = 0;

		while (1) {
			XAUDIO2_VOICE_STATE state;
			XAUDIO2_BUFFER audio_buf;

			#if !defined(DRV_XAUDIO28)
			IXAudio2SourceVoice_GetState(pSourceVoice, &state);
			#else
			IXAudio2SourceVoice_GetState(pSourceVoice, &state, XAUDIO2_VOICE_NOSAMPLESPLAYED);
			#endif
			if (state.BuffersQueued > 0)
				break;
			current_buf %= XAUDIO2_NUM_BUFFERS;
			if (Player_Paused_internal())
				VC_SilenceBytes((SBYTE *) buffers[current_buf], (ULONG) XAUDIO2_BUFFER_SIZE);
			else
				VC_WriteBytes((SBYTE *) buffers[current_buf], (ULONG) XAUDIO2_BUFFER_SIZE);
			memset(&audio_buf, 0, sizeof(XAUDIO2_BUFFER));
			audio_buf.AudioBytes = XAUDIO2_BUFFER_SIZE;
			audio_buf.pAudioData = buffers[current_buf];
			IXAudio2SourceVoice_SubmitSourceBuffer(pSourceVoice, &audio_buf, NULL);
			current_buf++;
			current_buf %= XAUDIO2_NUM_BUFFERS;
		}
		IXAudio2SourceVoice_Start(pSourceVoice, 0, 0);
		threadInUse = 1;
		ResumeThread(UpdateBufferHandle);
	}
}
Exemplo n.º 8
0
static void ALSA_Update(void)
{
	snd_pcm_playback_status_t status;
	int total, count;

	if (alsa_pcm_playback_status(pcm_h, &status) >= 0) {
		/* Update md_mixfreq if necessary */
		if (md_mixfreq != status.rate)
			md_mixfreq = status.rate;

		/* Using status.count would cause clicks, as this is always less than
		   the freespace  in the buffer - so compute how many bytes we can
		   afford */
		total = status.fragments * status.fragment_size - status.queue;
		if (total < fragmentsize)
			total = fragmentsize;
	} else
		total = fragmentsize;

	/* Don't send data if ALSA is too busy */
	while (total) {
		count = fragmentsize > total ? total : fragmentsize;
		total -= count;
		alsa_pcm_write(pcm_h,audiobuffer,VC_WriteBytes(audiobuffer,count));
	}
}
Exemplo n.º 9
0
static DWORD WINAPI updateBufferProc(LPVOID lpParameter)
{
	LPVOID pBlock1 = NULL, pBlock2 = NULL;
	DWORD soundBufferCurrentPosition, blockBytes1, blockBytes2;
	DWORD start;

	while (threadInUse) {
		if (WaitForSingleObject(notifyUpdateHandle,INFINITE)==WAIT_OBJECT_0) {

			if (!threadInUse) break;

			pSoundBuffer->lpVtbl->GetCurrentPosition
						(pSoundBuffer,&soundBufferCurrentPosition,NULL);

			if (soundBufferCurrentPosition < fragsize)
				start = fragsize;
			else
				start = 0;

			if (pSoundBuffer->lpVtbl->Lock
						(pSoundBuffer,start,fragsize,&pBlock1,&blockBytes1,
						 &pBlock2,&blockBytes2,0)==DSERR_BUFFERLOST) {	
				pSoundBuffer->lpVtbl->Restore(pSoundBuffer);
				pSoundBuffer->lpVtbl->Lock
						(pSoundBuffer,start,fragsize,&pBlock1,&blockBytes1,
						 &pBlock2,&blockBytes2,0);
			}

			MUTEX_LOCK(vars);
			if (Player_Paused_internal()) {
				VC_SilenceBytes((SBYTE*)pBlock1,(ULONG)blockBytes1);
				if (pBlock2)
					VC_SilenceBytes((SBYTE*)pBlock2,(ULONG)blockBytes2);
			} else {
				VC_WriteBytes((SBYTE*)pBlock1,(ULONG)blockBytes1);
				if (pBlock2)
					VC_WriteBytes((SBYTE*)pBlock2,(ULONG)blockBytes2);
			}
			MUTEX_UNLOCK(vars);
			
			pSoundBuffer->lpVtbl->Unlock
						(pSoundBuffer,pBlock1,blockBytes1,pBlock2,blockBytes2);
		}
	}
	return 0;
}
Exemplo n.º 10
0
static void Sun_Update(void)
{
	int done;

	done = VC_WriteBytes((char *)audiobuffer, fragsize);
	if (play_encoding == AUDIO_ENCODING_ULAW)
		unsignedtoulaw(audiobuffer, done);
	write(sndfd, audiobuffer, done);
}
Exemplo n.º 11
0
static void stdout_Update(void)
{
#ifdef WIN32
	_write
#else
	write
#endif
	     (1,audiobuffer,VC_WriteBytes((SBYTE*)audiobuffer,BUFFERSIZE));
}
Exemplo n.º 12
0
static void
moda_mmout_Update (void)
{
    written = 0;
    if (!buffer || bufsize == 0)
        return;

    written = VC_WriteBytes (buffer, bufsize);
}
Exemplo n.º 13
0
static void WAV_Update(void)
{
	ULONG done;

	done=VC_WriteBytes(audiobuffer,BUFFERSIZE);

	if (md_mode & DMODE_FLOAT) {
	/* O.S. - assuming same endian model for integer vs fp values	*/
		_mm_write_I_ULONGS((ULONG *) audiobuffer,done>>2,wavout);
	}
Exemplo n.º 14
0
int mod_decode(OutputBuffer * cb, DecoderControl * dc, char * path) {
	mod_Data * data;
	float time = 0.0;
	int ret;
	float secPerByte;

	if(mod_initMikMod() < 0) return -1;

	if(!(data = mod_open(path))) {
		ERROR("failed to open mod: %s\n", path);
		MikMod_Exit();
		return -1;
	}
	
	dc->audioFormat.bits = 16;
	dc->audioFormat.sampleRate = 44100;
	dc->audioFormat.channels = 2;
        getOutputAudioFormat(&(dc->audioFormat),&(cb->audioFormat));

	secPerByte = 1.0/((dc->audioFormat.bits*dc->audioFormat.channels/8.0)*
				(float)dc->audioFormat.sampleRate);
	
	dc->state = DECODE_STATE_DECODE;
	while(1) {
		if(dc->seek) {
			dc->seekError = 1;
			dc->seek = 0;
		}

		if(dc->stop) break;

		if(!Player_Active()) break;

		ret = VC_WriteBytes(data->audio_buffer, MIKMOD_FRAME_SIZE);
		time += ret*secPerByte;
		sendDataToOutputBuffer(cb, NULL, dc, 0, 
					(char *)data->audio_buffer, ret, time,
					0, NULL);
	}

	flushOutputBuffer(cb);

	mod_close(data);

	MikMod_Exit();

	if(dc->stop) {
		dc->state = DECODE_STATE_STOP;
		dc->stop = 0;
	}
	else dc->state = DECODE_STATE_STOP;

	return 0;
}
Exemplo n.º 15
0
static void sound_callback(void *buf, unsigned int reqn, void *pdata)
{
	(void)pdata;

	if (playing)
	{
		VC_WriteBytes(buf, reqn*4);
	}
	else
	{
		memset(buf, 0, reqn*4);
	}
}
Exemplo n.º 16
0
static void GP32_Update(void) {
	unsigned long bytesread;
#ifdef GP32_DEBUG
/*	gp_debug( 1, "Read bytes" );*/
#endif
	bytesread = VC_WriteBytes(GP32_buffer, GP32_buffersize);
#ifdef GP32_DEBUG
/*	gp_debug(1, "Read %d bytes", bytesread);*/
#endif
	if (!bytesread) return; /* exit if a whole buffer hasn't been read */

	gp_addRingsegment((unsigned short*)GP32_buffer);
}
Exemplo n.º 17
0
static void WIN_Update(void)
{
	ULONG done;

	while (buffersout<NUMBUFFERS) {
		done=VC_WriteBytes(buffer[nextbuffer],buffersize);
		if (!done) break;
		header[nextbuffer].dwBufferLength=done;
		waveOutWrite(hwaveout,&header[nextbuffer],sizeof(WAVEHDR));
		if (++nextbuffer>=NUMBUFFERS) nextbuffer%=NUMBUFFERS;
		++buffersout;
	}
}
Exemplo n.º 18
0
static Uint32 mm_mix_data(struct audio_stream *a_src, Sint32 *buffer,
 Uint32 len)
{
  struct mikmod_stream *mm_stream = (struct mikmod_stream *)a_src;
  Uint32 read_wanted = mm_stream->s.allocated_data_length -
   mm_stream->s.stream_offset;
  Uint8 *read_buffer = (Uint8 *)mm_stream->s.output_data +
   mm_stream->s.stream_offset;

  VC_WriteBytes((SBYTE*)read_buffer, read_wanted);
  sampled_mix_data((struct sampled_stream *)mm_stream, buffer, len);
  return 0;
}
Exemplo n.º 19
0
static void ANDROID_Update(void)
{
	if (playing)
	{
		VC_WriteBytes(mikmod_sndbuf, count * 2);
	}
    else
   	{
     // memset(mikmod_sndbuf, 0, BUFFERSIZE * 4);
    }
    
	    
   // boostSound(mikmod_sndbuf, BUFFERSIZE);
}
Exemplo n.º 20
0
int oslAudioCallback_AudioCallback_MOD(unsigned int i, void* buf, unsigned int length)			{
    //Set up playback
    //md_mixfreq = osl_modFrequency;
    //md_mixshift = osl_modShift;

    if (osl_modPlaying)
        VC_WriteBytes(buf, length << 2);
    else
        memset(buf, 0, length << 2);

    //Fin de la chanson ^^
    if (!Player_Active())
        return 0;
    return 1;
}
Exemplo n.º 21
0
static void OSLES_Update(void)
{
	unsigned long done = 1;

	while (buffersout < NUMBUFFERS) {
		done=VC_WriteBytes(buffer[nextbuffer],buffersize);
		if (!done) break;
        SLresult result;
        // enqueue another buffer
        result = (*bqPlayerBufferQueue)->Enqueue(bqPlayerBufferQueue, buffer[nextbuffer], done);
        if(SL_RESULT_SUCCESS != result)
        	break;
		if (++nextbuffer>=NUMBUFFERS) nextbuffer%=NUMBUFFERS;
		++buffersout;
	}
}
Exemplo n.º 22
0
static BOOL NDS_SW_PlayStart(void)
{
	if(VC_PlayStart())
		return 1;
	
	Player_SetPosition(0);
	
	ipc->prevTimer = 0;
	ipc->writeCursor = 0;
	ipc->readCursor = 0;

	int written = VC_WriteBytes(ipc->buffer, ipc->bufferSize);
	unsignedtosigned(ipc->buffer, written);

	DC_FlushRange(ipc, sizeof(*ipc));
	MikMod9_SendCommand(NDS_SW_CMD_START << 28);
	
	return 0;
}
Exemplo n.º 23
0
static int dc_update(void)
{
  int n;
  int buffer[512];

  /* Number of bytes in fifo */
  n = fifo_free() << 2;
  if (n < 0) {
    return INP_DECODE_ERROR;
  }

  if (!n) {
    return 0;
  }

  /* Not to much please. */
  if (n > (int)sizeof(buffer)) {
    n = sizeof(buffer);
  }

  n = VC_WriteBytes((void*)buffer, n);
  if (n < 0) {
    return INP_DECODE_ERROR;
  }
  if (!n) {
    /* $$$ ben: no more data ? probably the end ! */
    return INP_DECODE_END;
  }

  /* Get it back to sample */
  n >>= 2;

  if (fifo_write(buffer, n) != n) {
    /* This should not happen since we check the fifo above and no other
       thread fill it. */
    return INP_DECODE_ERROR;
  }

  return INP_DECODE_CONT;
}
Exemplo n.º 24
0
/* ARGSUSED */
void OS2_UpdateBufferThread(void *dummy)
{
	/* Run at timecritical priority */
	DosSetPriority(PRTYS_THREAD, PRTYC_TIMECRITICAL, PRTYD_MAXIMUM - 1, 0);

	while (!FinishPlayback) {
		ULONG count;
static	ULONG NextBuffer = 0;	/* next fragment to be filled */

		/* wait for play enable */
		DosWaitEventSem(Play, SEM_INDEFINITE_WAIT);
		/* wait for timer event */
		DosWaitEventSem(Update, SEM_INDEFINITE_WAIT);
		/* reset timer semaphore */
		DosResetEventSem(Update, &count);

		/* fill all free buffers */
		while (PlayList[NextBuffer].ulOperand3 >=
			   PlayList[NextBuffer].ulOperand2) {
			MUTEX_LOCK(vars);
			if (Player_Paused_internal())
				PlayList[NextBuffer].ulOperand2 =
				  VC_SilenceBytes((SBYTE *)PlayList[NextBuffer].ulOperand1,
								  BufferSize);
			else
				PlayList[NextBuffer].ulOperand2 =
				  VC_WriteBytes((SBYTE *)PlayList[NextBuffer].ulOperand1,
								BufferSize);
			MUTEX_UNLOCK(vars);
			/* Reset play offset, although it seems MMOS2 does it
			   automagically */
			PlayList[NextBuffer].ulOperand3 = 0;
			NextBuffer = (NextBuffer + 1) % FRAGMENTS;
		}
	}
	/* Tell main thread we're done */
	ThreadID = 0;
}
Exemplo n.º 25
0
static void NDS_SW_Update(void)
{
	DC_InvalidateRange(&ipc->readCursor, sizeof(ipc->readCursor));
	while(ipc->readCursor != ipc->writeCursor)
	{
		int todo = ipc->readCursor - ipc->writeCursor;
		if(todo < 0)
			todo = ipc->bufferSize - ipc->writeCursor;

		int written = VC_WriteBytes(ipc->buffer + ipc->writeCursor, todo);
		unsignedtosigned(ipc->buffer + ipc->writeCursor, written);
		
		int newCursor = ipc->writeCursor + written;
		if(ipc->writeCursor >= ipc->bufferSize)
			newCursor -= ipc->bufferSize;
		ipc->writeCursor = newCursor;
	}
	DC_FlushRange(&ipc->writeCursor, sizeof(ipc->writeCursor));
	
	// we send this afterwards to give arm7 as much time as possible
	// to update
	MikMod9_SendCommand(NDS_SW_CMD_UPDATE << 28);
}
Exemplo n.º 26
0
/* Buffer update thread (created and called by DART)
   This is a high-priority thread used to compute and update the audio stream,
   automatically created by the DART subsystem. We compute the next audio
   buffer and feed it to the waveaudio device. */
static LONG APIENTRY Dart_UpdateBuffers(ULONG ulStatus, PMCI_MIX_BUFFER pBuffer, ULONG ulFlags)
{
	/* sanity check */
	if (!pBuffer)
		return TRUE;
	
	/* if we have finished a buffer, we're ready to play a new one */
	if ((ulFlags == MIX_WRITE_COMPLETE) ||
		((ulFlags == (MIX_WRITE_COMPLETE | MIX_STREAM_ERROR)) &&
		 (ulStatus == ERROR_DEVICE_UNDERRUN))) {
		/* refill this audio buffer and feed it again */
		MUTEX_LOCK(vars);
		if (Player_Paused_internal())
			pBuffer->ulBufferLength =
					VC_SilenceBytes(pBuffer->pBuffer, BufferSize);
		else
			pBuffer->ulBufferLength =
					VC_WriteBytes(pBuffer->pBuffer, BufferSize);
		MUTEX_UNLOCK(vars);
		MixSetupParms.pmixWrite(MixSetupParms.ulMixHandle, pBuffer, 1);
	}
	return TRUE;
}
Exemplo n.º 27
0
/**
**  Load MikMod.
**
**  @param name   Filename of the module.
**  @param flags  Unused.
**
**  @return       Returns the loaded sample.
*/
CSample *LoadMikMod(const char *name, int flags)
{
	CSample *sample;
	MikModData *data;
	MODULE *module;
	CFile *f;
	char s[256];
	static int registered = 0;

	md_mode |= DMODE_STEREO | DMODE_INTERP | DMODE_SURROUND | DMODE_HQMIXER;
	MikMod_RegisterDriver(&drv_nos);
	if (!registered) {
		MikMod_RegisterAllLoaders();
		registered = 1;
	}

	strcpy_s(s, sizeof(s), name);
	f = new CFile;
	if (f->open(name, CL_OPEN_READ) == -1) {
		delete f;
		return NULL;
	}
	CurrentFile = f;

	MikMod_Init("");
	module = Player_LoadGeneric(&MReader, 64, 0);
	if (!module) {
		MikMod_Exit();
		f->close();
		delete f;
		return NULL;
	}

	if (flags & PlayAudioStream) {
		sample = new CSampleMikModStream;
		data = &((CSampleMikModStream *)sample)->Data;
	} else {
		sample = new CSampleMikMod;
		data = &((CSampleMikMod *)sample)->Data;
	}
	data->MikModFile = f;
	data->MikModModule = module;
	sample->Channels = 2;
	sample->SampleSize = 16;
	sample->Frequency = 44100;
	sample->Pos = 0;

	if (flags & PlayAudioStream) {
		sample->Len = 0;
		sample->Buffer = new unsigned char[SOUND_BUFFER_SIZE];

		Player_Start(data->MikModModule);
	} else {
		int read;
		int pos;

		// FIXME: need to find the correct length
		sample->Len = 55000000;
		sample->Buffer = new unsigned char[sample->Len];

		pos = 0;
		Player_Start(data->MikModModule);
		while (Player_Active()) {
			read = VC_WriteBytes((SBYTE *)sample->Buffer + pos,
				 sample->Len - pos);
			pos += read;
		}

		Player_Stop();
		Player_Free(data->MikModModule);
		MikMod_Exit();

		data->MikModFile->close();
		delete data->MikModFile;
	}

	return sample;
}
Exemplo n.º 28
0
static void NS_Update(void)
{
	if (zerobuf)
		VC_WriteBytes(zerobuf,ZEROLEN);
}
Exemplo n.º 29
0
/* SDY_Update - read data into buffer, called by Player_Update() from inside MikMod. */ 
static void SDY_Update(void)
{
	g_dwReaded = VC_WriteBytes(g_lpbyBuffer, g_dwReadBytes);
}
Exemplo n.º 30
0
static void HP_Update(void)
{
	write(fd,audiobuffer,VC_WriteBytes(audiobuffer,buffersize));
}