audio project
-
Saturday, May 19, 2012 9:34 PM
I am a long standing C and C++ programmer and I have used the <mmsystem.h> in the distant past to enable sound effects in a project.
I am influenced to some extent by owning an iPod personal audio device. Currently I use the 6th gen Nano with Klipsch earbuds. The listening environment is very high quality.
Now audio comes in a range of formats, the earbuds are obviously stereo as is music since the 1950, the Nano does not play video any more (used to).
One nuisance is compact disks that were mastered from cheap tape decks that have a very high noise floor.
The biggest nuisance is that Apple does not like rival formats much at all. It barely accepts media player by converting existing WMA files (that are not DRMed).
I use the Apple Lossless Audio Codec now that the code is open and royalty free. Its better than rivals in that it averages a tad more compression, clearly Apple worked on this hard to make it good.
Windows WAV seems to be the old loss-less format that has no compression which is fine as its easier to play.
Windows MVP 2011-12, XP, Vista, 7. Expanding into Windows Server 2008 R2, SQL Server, SharePoint, Cloud, Virtualization etc. etc.
Hardcore Games, Legendary is the only Way to Play
Developer | Windows IT | Chess | Economics | Vegan Advocate | PC Reviews
All Replies
-
Sunday, May 20, 2012 11:18 PM
If you are looking for a simplest solution, only one I can think of is to use GraphEdit plus to generate DirectShow code, where you use RenderFile with file name to create graph and then query interface and run graph. I am however not sure if there are some newer technologies.
You will have to "Setting Up the Build Environment" before you start.
1. Whiter than the white is UV bright! 2. Eat your vegetables or you are going to turn in to blobs of lazy fat! 3. Fruits won't cut it 4 wheel drive with levers to lock differentials was a hack
-
Sunday, May 20, 2012 11:33 PM
I have already found I will need to
#include "dshow.h"
to the project to be able to leverage the API.
I have some code already but I expect I may need to do a lot of work on the project.
my thinking is more like:
fstream ifile, ofile;
where ifile is the souce audio file, and ofile is the destination, this way I can use a temp file if I need to to decode something before playing it.
Windows MVP 2011-12, XP, Vista, 7. Expanding into Windows Server 2008 R2, SQL Server, SharePoint, Cloud, Virtualization etc. etc.
Hardcore Games, Legendary is the only Way to Play
Developer | Windows IT | Chess | Economics | Vegan Advocate | PC Reviews
-
Monday, May 21, 2012 12:08 AM
I have knowledge and resources to make what you want. I can give you a lib or dll that will convert any file windows media player can render on system in question and output to a PCM.
This is a source that uses my utilities to achieve what you want, and this is the really simple part but it can serve as a pseudo code if you decide to write it your self.
#pragma once #define _WIN32_WINNT 0x0501 #define WINVER 0x0501 #include <wchar.h> #include <DShow.h> #include <atlbase.h> #include <initguid.h> #include <dvdmedia.h> ...
// {00AE3339-554C-4bd4-9880-A4AC5307A29F} DEFINE_GUID(CLSID_PFCDump,
...
//Class works on passed pointers, it does not copy string names!!! class CConvertToPCM { public: //TODO: multiple sample rate //unsigned int *pSampleRate //pSampleRate[0] number of following sample rates //pSampleRate[1] sample rate - inftee then add as many resamplers as needed and generate as many pcm-s as required simultaneosely CConvertToPCM( const wchar_t *_pFileName, unsigned int _SampleRate, CLevelLogger *_pLevelLogger = NULL, const wchar_t *_pRequestedOutputFileName = NULL ) { ... /* //Find Source Filter ExitIfDSError( pDSPlus->FindFilter( 2, CLSID_AsyncReader ), "Searching for AsyncReader failed, exiting " ); //Find pin that this filter is connected to (reference is storred to pDSPlus->pUserPin[0] ) ExitIfDSError( pDSPlus->FindPinOnFilter( 2, PINDIR_OUTPUT, 1, TRUE, TRUE ), "Could not find audio decoder input pin, exiting " ); //Disconnect Source Filter ExitIfDSError( pDSPlus->DisconnectPin( pDSPlus->pGenericPin ), "Could not disconnect Async Source pin " ); //Remove Source Filter ExitIfDSError( pDSPlus->RemoveFilter( 2 ), "Removing AsyncReader failed, exiting " ); //Remove New Instance of Source Filter ExitIfDSError( pDSPlus->AddFilter( CLSID_AsyncReader, 2, L"Async Reader" ), "Could not add Async Reader, exiting " ); //Set Source File ExitIfDSError( pDSPlus->SetSourceFile( 2, L"D:\\2.mp3" ), "Could not set File Sink file name, exiting " ); //Find Output Pin on Async Reader ExitIfDSError( pDSPlus->FindPinOnFilter( 2, PINDIR_OUTPUT, 1 ), "Could not find Async Reader output pin, exiting " ); //Connect Filter ExitIfDSError( pDSPlus->ConnectPins( pDSPlus->pGenericPin, pDSPlus->pUserPin[0] ), "Could not connect Async Reader to Audio Decoder, exiting " ); //Start Rendering ExitIfDSError( pDSPlus->StartRendering(), "Running graph error, exiting " ); */ ReturnStauts = 1; } ~CConvertToPCM() const int GetConversionStatus() const wchar_t *GetPCMFileName() int BuildGraph() { pDSPlus = NULL; size_t tempSize_t; tempSize_t = wcslen( pFileName ) - 4; //Determine if file is allready PCM if( _wcsnicmp( &pFileName[tempSize_t], L".PCM", 4 ) ) {//No if( NULL != pRequestedOutputFileName ) { wmemcpy( PCMFileName, pRequestedOutputFileName, wcsnlen( pRequestedOutputFileName, MAX_PATH - 1 ) + 1 ); } else { wmemcpy( PCMFileName, pFileName, wcslen(pFileName) + 1 ); tempSize_t = wcsnlen( PCMFileName, MAX_PATH - 12 ); swprintf_s( &PCMFileName[tempSize_t], MAX_PATH - tempSize_t, L".%u.PCM", SampleRate ); } } else {//Yes if( NULL != pLevelLogger ) { pLevelLogger->Write( LOG_LEVEL_INFORMATION, "Convert to PCM, passed file name is PCM, generation skipped." ); } wmemcpy( PCMFileName, pFileName, wcslen(pFileName) + 1 ); goto PCMGenerationDone; } pDSPlus = new CDSPlus( pLevelLogger ); //Prepare Graph pDSPlus->CreateCaptureGraphBuilder2(); //Add file writer, connect to audio resampler unsigned int PCMDumpFilter = 1; ExitIfDSError( pDSPlus->AddFilter( CLSID_PFCDump, PCMDumpFilter, L"PCM Dump" ), "Could not add PCM Dump, exiting " ); /* //Render file, find audio renderer, remove audio renderer ExitIfDSError( pDSPlus->RenderFile(_pFileName), "Rendering File Failed, exiting " ); unsigned int DSAudioRenderer = 0; ExitIfDSError( pDSPlus->FindFilter( DSAudioRenderer, CLSID_DSoundRender ), "Could not find audio renderer, exiting " ); //If succedes output pin of decoder is stored in pUserPin[0] ExitIfDSError( pDSPlus->FindPinOnFilter( DSAudioRenderer, PINDIR_INPUT, 1, TRUE, TRUE ), "Could not find audio renderer input pin, exiting " ); ExitIfDSError( pDSPlus->RemoveFilter( DSAudioRenderer ), "Could not remove audio renderer, exiting" ); */ //Render file, find audio renderer, remove audio renderer ExitIfDSError( pDSPlus->RenderFile(pFileName), "Rendering File Failed, exiting " ); //If succedes output pin of decoder is stored in pUserPin[0] ExitIfDSError( pDSPlus->FindPinOnFilter( PCMDumpFilter, PINDIR_INPUT, 1, TRUE, TRUE ), "Could not find audio renderer input pin, exiting " ); //Disconnect PCMDumpFilter Input Pin ExitIfDSError( pDSPlus->DisconnectPin( pDSPlus->pGenericPin ), "Could not disconnect PCMDumpFilter pin " ); ExitIfDSError( pDSPlus->DisconnectPin( pDSPlus->pUserPin[0] ), "Could not disconnect decoder pin "); //Add Audio Resampler, configure audio resampler, connect audio resampler to audio decoder ... //Connect PCM Dump Filter to MC Audio Resampler ExitIfDSError( pDSPlus->SetSinkFile( PCMDumpFilter, PCMFileName, true ), "Could not set File Sink file name, exiting " ); //ExitIfDSError( pDSPlus->FindPinOnFilter( PCMDumpFilter, PINDIR_INPUT ), "Could not find input pin on PCM Dump, exiting " ); ExitIfDSError( pDSPlus->ConnectFilters( MCAudioResampler, PCMDumpFilter ), "Could not connect MC Audio Resampler to PCM Dump, exiting " ); PCMGenerationDone:; return 1; } int StartConversion() { //Running graph and wait for exit - this must be new thread ExitIfDSError( pDSPlus->StartRendering(), "Running graph error, exiting " ); ...
return 1; } private: CDSPlus *pDSPlus; wchar_t PCMFileName[ MAX_PATH + 1 ]; unsigned int SampleRate; const wchar_t *pFileName; CLevelLogger *pLevelLogger; const wchar_t *pRequestedOutputFileName; // 1 : Conversion 0K. // -1 : Conversion failed int ReturnStauts; }; #undef ExitIfDSError
1. Whiter than the white is UV bright! 2. Eat your vegetables or you are going to turn in to blobs of lazy fat! 3. Fruits won't cut it 4 wheel drive with levers to lock differentials was a hack
- Edited by D3F84U Monday, May 21, 2012 12:16 AM
- Marked As Answer by Jesse JiangMicrosoft Contingent Staff, Moderator Wednesday, May 30, 2012 3:21 AM
-
Monday, May 21, 2012 1:39 AM
Thanks, that is a useful template to work from.
The idea I have is to convert various lossless formats to ALAC as part of a larger block of code
ideally leveraging any existing filter for a stream is helpful
ALAC is now royalty free so its respectable now
seems WMA has a lossless version too, so there are a lot of things to consider
Windows MVP 2011-12, XP, Vista, 7. Expanding into Windows Server 2008 R2, SQL Server, SharePoint, Cloud, Virtualization etc. etc.
Hardcore Games, Legendary is the only Way to Play
Developer | Windows IT | Chess | Economics | Vegan Advocate | PC Reviews
-
Monday, May 21, 2012 2:47 AM
If filter is available as .ax or .dll for DirectShow, you have documentation with CLSIDs of supported interfaces and properties of filter and it's pins you can then use that filter.
1. Whiter than the white is UV bright! 2. Eat your vegetables or you are going to turn in to blobs of lazy fat! 3. Fruits won't cut it 4 wheel drive with levers to lock differentials was a hack
-
Monday, May 21, 2012 3:47 AM
looks like lots of work for this project, should be entertaining as it will keep me busy for the rest of the year anyway
Windows MVP 2011-12, XP, Vista, 7. Expanding into Windows Server 2008 R2, SQL Server, SharePoint, Cloud, Virtualization etc. etc.
Hardcore Games, Legendary is the only Way to Play
Developer | Windows IT | Chess | Economics | Vegan Advocate | PC Reviews
-
Monday, May 21, 2012 7:02 AMModerator
Hi Vegan,
Also, You can use Media Foundation to program with audio. Please check this
http://msdn.microsoft.com/en-us/library/windows/desktop/ms697062(v=vs.85).aspx
Best regards,
Jesse
Jesse Jiang [MSFT]
MSDN Community Support | Feedback to us
- Marked As Answer by Jesse JiangMicrosoft Contingent Staff, Moderator Wednesday, May 30, 2012 3:21 AM
-
Monday, May 21, 2012 3:53 PM
I did have hard time writing that code.
This link is to Media Foundation sample that has similar functionality as code I posted, and is even better, because it transcodes to WMA. That means that most likely you just have to do a setup (using documentation) of a transcoding component in order to transcode to lossless format.
Shows how to reencode a media file to Windows Media format.
1. Whiter than the white is UV bright! 2. Eat your vegetables or you are going to turn in to blobs of lazy fat! 3. Fruits won't cut it 4 wheel drive with levers to lock differentials was a hack
- Edited by D3F84U Monday, May 21, 2012 3:55 PM
- Marked As Answer by Jesse JiangMicrosoft Contingent Staff, Moderator Wednesday, May 30, 2012 3:21 AM

