コード例 #1
0
ファイル: wave-file.c プロジェクト: argasek/morphine
int main(int argc, char **argv) {
  int i;

  for (i = 1; i < argc; i++) {
    WaveFileT file;

    if (WaveFileOpen(&file, argv[i])) {
      WaveFilePrint(&file, argv[i]);
      WaveFileClose(&file);
    }
  }

  return 0;
}
コード例 #2
0
static EAS_RESULT PlayFile (EAS_DATA_HANDLE easData, const char* filename, const char* outputFile, const S_EAS_LIB_CONFIG *pLibConfig, void *buffer, EAS_I32 bufferSize)
{
	EAS_HANDLE handle;
	EAS_RESULT result, reportResult;
	EAS_I32 count;
	EAS_STATE state;
	EAS_I32 playTime;
	char waveFilename[256];
	WAVE_FILE *wFile;
	EAS_INT i;
	EAS_PCM *p;
	EAS_FILE file;

	/* determine the name of the output file */
	wFile = NULL;
	if (outputFile == NULL)
	{
		StrCopy(waveFilename, filename, sizeof(waveFilename));
		if (!ChangeFileExt(waveFilename, "wav", sizeof(waveFilename)))
		{
			{ /* dpp: EAS_ReportEx(_EAS_SEVERITY_ERROR, "Error in output filename %s\n", waveFilename); */ }
			return EAS_FAILURE;
		}
		outputFile = waveFilename;
	}

	/* call EAS library to open file */
	file.path = filename;
	file.fd = 0;
	if ((reportResult = EAS_OpenFile(easData, &file, &handle)) != EAS_SUCCESS)
	{
		{ /* dpp: EAS_ReportEx(_EAS_SEVERITY_ERROR, "EAS_OpenFile returned %ld\n", reportResult); */ }
		return reportResult;
	}

	/* prepare to play the file */
	if ((result = EAS_Prepare(easData, handle)) != EAS_SUCCESS)
	{
		{ /* dpp: EAS_ReportEx(_EAS_SEVERITY_ERROR, "EAS_Prepare returned %ld\n", result); */ }
		reportResult = result;
	}

	/* get play length */
	if ((result = EAS_ParseMetaData(easData, handle, &playTime)) != EAS_SUCCESS)
	{
		{ /* dpp: EAS_ReportEx(_EAS_SEVERITY_ERROR, "EAS_ParseMetaData returned %ld\n", result); */ }
		return result;
	}
	EAS_ReportEx(_EAS_SEVERITY_NOFILTER, 0xe624f4d9, 0x00000005 , playTime / 1000, playTime % 1000);

	if (reportResult == EAS_SUCCESS)
	{
		/* create the output file */
		wFile = WaveFileCreate(outputFile, pLibConfig->numChannels, pLibConfig->sampleRate, sizeof(EAS_PCM) * 8);
		if (!wFile)
		{
			{ /* dpp: EAS_ReportEx(_EAS_SEVERITY_ERROR, "Unable to create output file %s\n", waveFilename); */ }
			reportResult = EAS_FAILURE;
		}
	}

	/* rendering loop */
	while (reportResult == EAS_SUCCESS)
	{

		/* we may render several buffers here to fill one host buffer */
		for (i = 0, p = buffer; i < NUM_BUFFERS; i++, p+= pLibConfig->mixBufferSize * pLibConfig->numChannels)
		{
			
			/* get the current time */
			if ((result = EAS_GetLocation(easData, handle, &playTime)) != EAS_SUCCESS)
			{
				{ /* dpp: EAS_ReportEx(_EAS_SEVERITY_ERROR, "EAS_GetLocation returned %d\n",result); */ }
				if (reportResult == EAS_SUCCESS)
					reportResult = result;
				break;
			}
			{ /* dpp: EAS_ReportEx(_EAS_SEVERITY_DETAIL, "Parser time: %d.%03d\n", playTime / 1000, playTime % 1000); */ }

			/* render a buffer of audio */
			if ((result = EAS_Render(easData, p, pLibConfig->mixBufferSize, &count)) != EAS_SUCCESS)
			{
				{ /* dpp: EAS_ReportEx(_EAS_SEVERITY_ERROR, "EAS_Render returned %d\n",result); */ }
				if (reportResult == EAS_SUCCESS)
					reportResult = result;
			}
		}

		if (result == EAS_SUCCESS)
		{
			/* write it to the wave file */
			if (WaveFileWrite(wFile, buffer, bufferSize) != bufferSize)
			{
				{ /* dpp: EAS_ReportEx(_EAS_SEVERITY_ERROR, "WaveFileWrite failed\n"); */ }
				reportResult = EAS_FAILURE;
			}
		}

		if (reportResult == EAS_SUCCESS)
		{
			/* check stream state */
			if ((result = EAS_State(easData, handle, &state)) != EAS_SUCCESS)
			{
				{ /* dpp: EAS_ReportEx(_EAS_SEVERITY_ERROR, "EAS_State returned %d\n", result); */ }
				reportResult = result;
			}

			/* is playback complete */
			if ((state == EAS_STATE_STOPPED) || (state == EAS_STATE_ERROR))
				break;
		}
	}

	/* close the output file */
	if (wFile)
	{
		if (!WaveFileClose(wFile))
		{
			{ /* dpp: EAS_ReportEx(_EAS_SEVERITY_ERROR, "Error closing wave file %s\n", waveFilename); */ }
			if (reportResult == EAS_SUCCESS)
				result = EAS_FAILURE;
		}
	}
	
	/* close the input file */
	if ((result = EAS_CloseFile(easData,handle)) != EAS_SUCCESS)
	{
		{ /* dpp: EAS_ReportEx(_EAS_SEVERITY_ERROR, "EAS_Close returned %ld\n", result); */ }
		if (reportResult == EAS_SUCCESS)
			result = EAS_FAILURE;
	}

	return reportResult;
} /* end PlayFile */