Exemplo n.º 1
0
static bool AudioOpen()
{
	MSU1.MSU1_STATUS |= AudioError;

	AudioClose();

	char ext[_MAX_EXT];
	snprintf(ext, _MAX_EXT, "-%d.pcm", MSU1.MSU1_CURRENT_TRACK);

    audioStream = S9xMSU1OpenFile(ext);
	if (audioStream)
	{
		if (GETC_STREAM(audioStream) != 'M')
			return false;
		if (GETC_STREAM(audioStream) != 'S')
			return false;
		if (GETC_STREAM(audioStream) != 'U')
			return false;
		if (GETC_STREAM(audioStream) != '1')
			return false;

        READ_STREAM((char *)&audioLoopPos, 4, audioStream);
		audioLoopPos = GET_LE32(&audioLoopPos);
		audioLoopPos <<= 2;
		audioLoopPos += 8;

        MSU1.MSU1_AUDIO_POS = 8;

		MSU1.MSU1_STATUS &= ~AudioError;
		return true;
	}

	return false;
}
Exemplo n.º 2
0
VOID GameOverInit()
{
	global.finalTime = global.timePass();
	if (global.blood <= 0)
	{
		AudioClose();
		PlaySound(_T("res/sound/falldown.wav"), NULL, SND_ASYNC | SND_FILENAME);
	}

	UINT totalCombo = 0;
	DOUBLE finalScore = 0.;
	for (int i = 0; i < 4; i++)
	{
		totalCombo += global.barriers[i].size();
		for (size_t j = 0; j < global.barriers[i].size(); j++)
		{
			auto keyToBarrier = std::lower_bound(global.keySequence[i].begin(), global.keySequence[i].end(), global.barriers[i][j].msecs);
			INT delta = INT_MAX;
			if (keyToBarrier != global.keySequence[i].begin())
				delta = abs(*(keyToBarrier - 1) - global.barriers[i][j].msecs);
			if (keyToBarrier != global.keySequence[i].end())
				delta = min(delta, abs(*keyToBarrier - global.barriers[i][j].msecs));
			if (delta <= global.currSong().msPerBeat * 0.4 / 4.)
				finalScore += 1;
			else if (delta <= global.currSong().msPerBeat * 0.4 / 3.)
				finalScore += 0.95;
			else if (delta <= global.currSong().msPerBeat * 0.4 / 2.)
				finalScore += 0.6;
		}
	}

	global.finalScore = finalScore / totalCombo;

	global.status = global.GS_GAMEOVER;
}
Exemplo n.º 3
0
void S9xResetMSU(void)
{
	MSU1.MSU1_STATUS		= 0;
	MSU1.MSU1_DATA_SEEK		= 0;
	MSU1.MSU1_DATA_POS		= 0;
	MSU1.MSU1_TRACK_SEEK	= 0;
	MSU1.MSU1_CURRENT_TRACK = 0;
	MSU1.MSU1_RESUME_TRACK	= 0;
	MSU1.MSU1_VOLUME		= 0;
	MSU1.MSU1_CONTROL		= 0;
	MSU1.MSU1_AUDIO_POS		= 0;
	MSU1.MSU1_RESUME_POS	= 0;


	bufPos				= 0;
	bufBegin			= 0;
	bufEnd				= 0;

	partial_frames = 0;

	DataClose();

	AudioClose();

	Settings.MSU1 = S9xMSU1ROMExists();
}
int main(int argc, char* argv[])
{
    int           rc;
    unsigned int  i;

    memset(recordedSamples, 0, N_SAMPLES_TO_RECORD * sizeof(typeSample));

    rc = AudioSetInputFormat(SAMPLING_RATE, N_CHANNELS_PER_TUPLE);
    if (rc != 0)
    {
        printf("ERROR: AudioSetInputFormat() returns %d\n", rc);
        exit(1);
    }

    rc = AudioOpen();
    if (rc < 0)
    {
        printf("ERROR: AudioOpen() returns %d (device handle/ID)\n", rc);
        exit(1);
    }
        
    i = 0;
    while (i <= N_SAMPLES_TO_RECORD - N_SAMPLES_PER_BUFFER)
    {
        rc = AudioRead(&(recordedSamples[i]), N_FRAMES_PER_BUFFER);
        if (rc > 0)
            i += (rc * N_TUPLES_PER_FRAME * N_CHANNELS_PER_TUPLE);
        else
            printf("ERROR: AudioRead() returns %d\n", rc);
    }

    rc = AudioClose();
    if (rc != 0)
    {
        printf("ERROR: AudioClose() returns %d\n", rc);
        exit(1);
    }

    /* write to file  */
    {
        FILE *fpOutput;
        char *szFilename = "output_AudioHardwareRecord.pcm";

        fpOutput = fopen(szFilename, "wb");
        if (fpOutput == NULL)
        {
            printf("ERROR: cannot create '%s'\n", szFilename);
            exit(1);
        }
        fwrite(recordedSamples, sizeof(typeSample), i, fpOutput);
        fclose(fpOutput);
    }

    return 0;
}
Exemplo n.º 5
0
void MediaEngine::closeMedia() {
	closeContext();
	if (m_pdata)
		delete m_pdata;
	if (m_demux)
		delete m_demux;
	m_pdata = 0;
	m_demux = 0;
	AudioClose(&m_audioContext);
	m_isVideoEnd = false;
}
Exemplo n.º 6
0
void S9xResetMSU(void)
{
	MSU1.MSU1_STATUS		= 0;
	MSU1.MSU1_DATA_SEEK		= 0;
	MSU1.MSU1_DATA_POS		= 0;
	MSU1.MSU1_TRACK_SEEK	= 0;
	MSU1.MSU1_CURRENT_TRACK = 0;
	MSU1.MSU1_RESUME_TRACK	= 0;
	MSU1.MSU1_VOLUME		= 0;
	MSU1.MSU1_CONTROL		= 0;
	MSU1.MSU1_AUDIO_POS		= 0;
	MSU1.MSU1_RESUME_POS	= 0;

	if (msu_resampler)
		msu_resampler->clear();

	partial_frames = 0;

	DataClose();

	AudioClose();

	Settings.MSU1 = S9xMSU1ROMExists();
}
Exemplo n.º 7
0
void S9xMSU1DeInit(void)
{
	DataClose();
	AudioClose();
}
Exemplo n.º 8
0
AuCtx::~AuCtx(){
	if (decoder){
		AudioClose(&decoder);
		decoder = NULL;
	}
};
void *AcquisitionThread ( void *data )
{
  int doneWaiting = 0;
  audioinSample   *CodecBuffer;
  long            x;
  long            y;
#ifdef AUDIOIN_SUPPORT_CALLBACK
  AUDIOIN_H       *phAudioIn = (AUDIOIN_H *)data;
  AUDIOIN_WAVEHDR *pwhdr;
#endif


  pthread_mutex_lock ( &gAudioMutex );

  //signal to tell that our thread is now running.
  if ( pthread_cond_signal ( &gThreadRunning ) != 0 )
  {
    pthread_mutex_unlock ( &gAudioMutex );
    PLogError ( "Audio In Error pthread_cond_signal\n" );
    exit ( 1 );
  }
  gThreadRunningSignaled = 1;

  while( 1 )
  {

    while (!doneWaiting)
    {
      int rc = pthread_cond_wait(&gOpenExCalled, &gAudioMutex);
      switch (rc)
      {
        case 0:
          if (!gOpenExCalledSignaled)
          {
            // Avoid spurious wakeups
            continue;
          }
          else
          {
            gOpenExCalledSignaled = 0;
            doneWaiting = 1;
            break;
          }
          break;
        default:
          PLogError ( "Audio In Error pthread_cond_signal\n" );
          pthread_mutex_unlock(&gAudioMutex);
          return ( (void *)NULL );
      }
    }
    doneWaiting = 0;
    pthread_mutex_unlock(&gAudioMutex);

    if( gTerminateThread == 1 )
      break;



    /* buffer of 16 bits samples */
    CodecBuffer = (audioinSample *)malloc ( gCodecFragmentSizeInFrames * sizeof ( audioinSample ) );

    if ( CodecBuffer == NULL )
    {
      PLogError ( "Audio In Error malloc\n" );
      exit ( 1 );
    }
    pwhdr = malloc ( sizeof ( AUDIOIN_WAVEHDR ) );

    if ( pwhdr == NULL )
    {
      PLogError ( "Audio In Error malloc\n" );
      exit ( 1 );
    }

    while ( !getClose ( ) )
    {

      int iReadFrames  = 0;  /* number of frames acquired by the codec */
      /* NOTE: here a frame is comprised of 1 sample if mono, 2 samples if stereo, etc */
      int iReadSamples = 0;  /* number of samples acquired by the codec */
      int frames_to_read;     /* Actual number to read */
      int frames_read;        /* Frames read on one read */

      iReadFrames = 0;

      do
      {
        frames_to_read = gCodecFragmentSizeInFrames - iReadFrames;
        /* AudioRead() - output: number of frames (mono: 1 sample, stereo: 2 samples)*/
        frames_read = AudioRead ( CodecBuffer + iReadFrames, frames_to_read );

        if ( frames_read > 0 )
          iReadFrames += frames_read;
      }
      while ( ( iReadFrames < gCodecFragmentSizeInFrames ) && ( frames_read > 0 ) );
      iReadSamples = iReadFrames;

      if ( getRecord ( ) )  /* else continue to read from driver but discard samples */
      {
        if ( iReadSamples < 0 )
        {
          iReadSamples = 0;
          gAudioInInfo.eStatusInfo = AUDIOIN_HWOVERRUN;
        }
        else
        {
#ifdef FILTER_ON
          /* x: index for start of input samples; y: index for output sample */
          for ( x = 0, y = 0; x < iReadSamples; x += pFIR->factor_down )
          {
            FIR_downsample ( pFIR->factor_down, &( CodecBuffer[x] ), &( CodecBuffer[y++] ), pFIR );
          }
          /* update the number samples */
          iReadSamples = y;
#endif
          pthread_mutex_lock ( &gAudioMutex );

          if ( gAudioInInfo.u32SamplesAvailable + iReadSamples > SAMPLES_BUFFER_SIZE )
          {
            gAudioInInfo.u32SamplesAvailable = SAMPLES_BUFFER_SIZE;
            gAudioInInfo.eStatusInfo = AUDIOIN_FIFOOVERRUN;
          }
          else
          {
            if ( gAudioInInfo.u32SamplesAvailable + iReadSamples > SAMPLES_BUFFER_HIGH_WATERMARK )
            {
              gAudioInInfo.eStatusInfo = AUDIOIN_HIGHWATERMARK;
            }
            else if ( gAudioInInfo.eStatusInfo != AUDIOIN_FIFOOVERRUN )
            {
              gAudioInInfo.eStatusInfo = AUDIOIN_NORMAL;
            }
            gAudioInInfo.u32SamplesAvailable += iReadSamples;
          }
          if ( gWriteIndexPointer + iReadSamples <= SAMPLES_BUFFER_SIZE )
          {
            memcpy ( &( gSamplesBufferCircularFifo[gWriteIndexPointer] ), CodecBuffer,
                iReadSamples * sizeof ( audioinSample ) );
            gWriteIndexPointer += iReadSamples;

            if ( gWriteIndexPointer >= SAMPLES_BUFFER_SIZE )
              gWriteIndexPointer = 0;
          }
          else
          {
            int NbToCopy;

            NbToCopy = SAMPLES_BUFFER_SIZE - gWriteIndexPointer;
            memcpy ( &( gSamplesBufferCircularFifo [gWriteIndexPointer] ), CodecBuffer,
                NbToCopy * sizeof ( audioinSample ) );
            gWriteIndexPointer = 0;
            memcpy ( gSamplesBufferCircularFifo, &( CodecBuffer [NbToCopy] ),
                ( iReadSamples-NbToCopy ) * sizeof ( audioinSample ) );
            gWriteIndexPointer = iReadSamples - NbToCopy;
          }

#ifdef AUDIOIN_SUPPORT_CALLBACK
          /* Callback notification.  Ideally this audio acquisition thread should be very lean.
             It should simply read from the low level driver, store the filtered samples in
             the FIFO, then go back to reading from the driver.  The additional data copy
             for the callback function is ok despite the overhead incurred, but only because
             there's some buffering done by the low level driver.  This design should be
             revisited to make it more general purpose.
             */
          if ( gpCallback != NULL )
          {
            pwhdr->nBufferLength  = iReadSamples * sizeof ( audioinSample );
            pwhdr->nBytesRecorded = pwhdr->nBufferLength;
            pwhdr->status = AUDIOIN_NORMAL;
            pwhdr->pData = CodecBuffer;
            /* pass samples to callback function who should deallocate the buffer and structure */
            gpCallback ( *phAudioIn, AUDIOIN_MSG_DATA, gpCallbackInstance, pwhdr, NULL );
          }
#endif
          /* samples are available to read */
          pthread_mutex_unlock ( &gAudioMutex );
          timer.tv_sec = 0;
          timer.tv_usec = 200;
          select ( 0, NULL, NULL, NULL, &timer );
        }
      } /* if (getRecord()) */

    } /* while (!getClose()) */
    if ( AudioClose ( ) !=0 )
    {
      PLogError ( "Audio In Error Closing Hardware\n" );
    }
    free ( CodecBuffer );

    pthread_mutex_lock ( &gAudioMutex );
    //signal to tell that our thread is now running.
    if ( pthread_cond_signal ( &gCloseCalled ) != 0 )
    {
      pthread_mutex_unlock ( &gAudioMutex );
      PLogError ( "Audio In Error pthread_cond_signal\n" );
      exit ( 1 );
    }
    gCloseCalledSignaled = 1;
  }

  pthread_exit ( (void *)NULL );
  return ( (void *)NULL );
}