Add to Favorites    Make Home Page 14554 Online  
 Language Categories  
 Our Services  

Home » C Home » Multimedia and Sound Home » WAV file player

A D V E R T I S E M E N T

Search Projects & Source Codes:

Title WAV file player
Author T.V.Gokul
Author Email gokultv_ece [at] rediffmail.com
Description This is a simple WAV file player which interacts your Sound
card(of type SoundBlaster).It can play only 8-bit Mono PCM WAVe file
whose
time lenght is around 1 secs.,the programmers can extend for more
timelenght.It works fine in Pure 16-bit DOS Mode
Category C » Multimedia and Sound
Hits 389439
Code Select and Copy the Code
/************************************************************************* *** ** WARNING: You need a HUGE memory model to run this. ** ************************************************************************** **/ /************************************************************************* *** ********Created by T.V.Gokul.Thiagarajar College of Engineering-Madurai****** If U have any Queries,Feel free to mailme at:[email protected]******/ //Include files #include "ALLOC.H" #include "DOS.H" #include "CONIO.H" #include "STDIO.H" void main() { char *name; printf(" Enter the file name...:"); scanf("%s",name); playwav(name,1.0); } void playwav(char wavefile[14],float delaytime); struct WaveData { unsigned int SoundLength, Frequency; char *Sample; }; struct HeaderType { long RIFF; //RIFF header char NI1 [18]; //not important unsigned int Channels; //channels 1 = mono; 2 = stereo long Frequency; //sample frequency char NI2 [6]; //not important char BitRes; //bit resolution 8/16 bit char NI3 [12]; //not important } Header; struct WaveData Voice; //Pointer to wave file unsigned int Base; //Sound Blaster base address char WaveFile [25]; //File name for the wave file to be played /************************************************************************* *** ** Checks to see if a Sound Blaster exists at a given address, returns ** ** true if Sound Blaster found, false if not. ** ************************************************************************** **/ int ResetDSP(unsigned int Test) { //Reset the DSP outportb (Test + 0x6, 1); delay(10); outportb (Test + 0x6, 0); delay(10); //Check if (reset was succesfull if ((inportb(Test + 0xE) & 0x80 == 0x80) && (inportb(Test + 0xA) == 0xAA)) { //DSP was found Base = Test; return (1); } else //No DSP was found return (0); } /************************************************************************* *** ** Send a byte to the DSP (Digital Signal Processor) on the Sound Blaster ** ************************************************************************** **/ void WriteDSP(unsigned char Value) { //Wait for the DSP to be ready to accept data while ((inportb(Base + 0xC) & 0x80) == 0x80); //Send byte outportb (Base + 0xC, Value); } /************************************************************************* *** ** Plays a part of the memory ** ************************************************************************** **/ void PlayBack (struct WaveData *Wave) { long LinearAddress; unsigned int Page, OffSet; unsigned char TimeConstant; TimeConstant = (65536 - (256000000 / Wave->Frequency)) >> 8; WriteDSP(0x40); //DSP-command 40h - Set sample frequency WriteDSP(TimeConstant); //Write time constant //Convert pointer to linear address LinearAddress = FP_SEG (Wave->Sample); LinearAddress = (LinearAddress << 4) + FP_OFF (Wave->Sample); Page = LinearAddress >> 16; //Calculate page OffSet = LinearAddress & 0xFFFF; //Calculate offset in the page /* Note - this procedure only works with DMA channel 1 */ outportb (0x0A, 5); //Mask DMA channel 1 outportb (0x0C, 0); //Clear byte pointer outportb (0x0B, 0x49); //Set mode /* The mode consists of the following: 0x49 = binary 01 00 10 01 | | | | | | | +- DMA channel 01 | | +---- Read operation (the DSP reads from memory) | +------- Single cycle mode +---------- Block mode */ outportb (0x02, OffSet & 0x100); //Write the offset to the DMA controller outportb (0x02, OffSet >> 8); outportb (0x83, Page); //Write the page to the DMA controller outportb (0x03, Wave->SoundLength & 0x100); outportb (0x03, Wave->SoundLength >> 8); outportb (0x0A, 1); //Unmask DMA channel WriteDSP(0x14); // DSP-command 14h - Single cycle playback WriteDSP(Wave->SoundLength & 0xFF); WriteDSP(Wave->SoundLength >> 8); } /************************************************************************* *** ** Loads a wave file into memory. ** ** This procedure expects a _very_ standard wave header. ** ** It doesn't perform much error checking. ** ************************************************************************** **/ int LoadVoice (struct WaveData *Voice, char *FileName) { FILE *WAVFile; //If it can't be opened... WAVFile = fopen(FileName, "rb"); if (WAVFile == NULL) { //..display error message return (0); } //Return length of file for sound length minus 48 bytes for .WAV header fseek(WAVFile, 0L, SEEK_END); Voice->SoundLength = ftell (WAVFile) - 48; fseek(WAVFile, 0L, SEEK_SET); //Check RIFF header if (Voice->SoundLength > 32000) { if (Voice->SoundLength > 64000) { Voice->SoundLength = 64000; } } free(Voice->Sample); Voice->Sample = (char *)malloc(Voice->SoundLength); //Assign memory if (!Voice->Sample) { return (0); } //Load the sample data fread(&Header, 46, 1, WAVFile); //Check RIFF header if (Header.RIFF != 0x46464952) { printf ("Not a wave file "); return (0); } //Check channels if (Header.Channels != 1) { printf ("Not a mono wave file "); return (0); } //Check bit resolution if (Header.BitRes != 8) { printf ("Not an 8-bit wave file "); return (0); } Voice->Frequency = Header.Frequency; //Load the sample data fread(Voice->Sample, Voice->SoundLength + 2, 1, WAVFile); fclose (WAVFile); //Close the file return (1); } void playwav (char wavefile[14], float delaytime ) { delaytime=1.0; if (ResetDSP (0x220)) { //at 220h printf (""); } else { if (ResetDSP (0x240)) { //at 240h printf (""); } else { //or none at all printf (""); return; } } //Load wave file if (LoadVoice (&Voice, wavefile)) { //Start playback PlayBack (&Voice); delay(delaytime*1000); //Stops DMA-transfer WriteDSP (0xD0); } }

Related Source Codes

Script Name Author
The Game Opposite as seen on Nokia 2300 Mobile Manikanta
RECURSIVE BALANCED QUICK SORT ashish
Radix Sort ashish
Change your mouse pointer Ashim
The blinking star Shashank
Data Validation Crylittlebaby
To search a file by giving file type like mp3 or mpeg or doc Prashanth SR
Menus Demonstration B.Chidhambaram
Employee Database Project Using C. Reenku Raman Nayak
Creating a Lexical Analyzer in c fahad bader al-buhairi �դ ?�� ��??���
Calendar Program Omkar & Devendra
Stop double Process for start in C Cedrik Jurak
Stop double Process for start in C Cedrik Jurak
Time Scheduler Atiq Anwar
A timepass game between atmost two players Rahul Roy

A D V E R T I S E M E N T




Google Groups Subscribe to SourceCodesWorld - Techies Talk
Email:

Free eBook - Interview Questions: Get over 1,000 Interview Questions in an eBook for free when you join JobsAssist. Just click on the button below to join JobsAssist and you will immediately receive the Free eBook with thousands of Interview Questions in an ebook when you join.

New! Click here to Add your Code!


ASP Home | C Home | C++ Home | COBOL Home | Java Home | Pascal Home
Source Codes Home Page

 Advertisements  

Google Search

Google

Source Codes World.com is a part of Vyom Network.

Vyom Network : Web Hosting | Dedicated Server | Free SMS, GRE, GMAT, MBA | Online Exams | Freshers Jobs | Software Downloads | Interview Questions | Jobs, Discussions | Placement Papers | Free eBooks | Free eBooks | Free Business Info | Interview Questions | Free Tutorials | Arabic, French, German | IAS Preparation | Jokes, Songs, Fun | Free Classifieds | Free Recipes | Free Downloads | Bangalore Info | Tech Solutions | Project Outsourcing, Web Hosting | GATE Preparation | MBA Preparation | SAP Info | Software Testing | Google Logo Maker | Freshers Jobs

Sitemap | Privacy Policy | Terms and Conditions | Important Websites
Copyright ©2003-2024 SourceCodesWorld.com, All Rights Reserved.
Page URL: http://www.sourcecodesworld.com/source/show.asp?ScriptID=567


Download Yahoo Messenger | Placement Papers | Free SMS | C Interview Questions | C++ Interview Questions | Quick2Host Review