displaying sample values from a wave file

This is a discussion on displaying sample values from a wave file within the C Programming forums, part of the General Programming Boards category; Hi i was hoping someone would be able to help me out with the following problem i've been stuck with ...

  1. #1
    Registered User
    Join Date
    Mar 2006
    Posts
    19

    displaying sample values from a wave file

    Hi i was hoping someone would be able to help me out with the following problem i've been stuck with for a while. I've researched wave files and using snippets of code have put together a program to display information about a wave file. I'm able to open a wave file using C and access various chunks to get values. The file im working with is 16 bit uncompressed PCM and although i'm able to access the data chunk i can't figure out how to get the program to display back sample values in unsigned integer format. Any help with this would be greatly appreciated

  2. #2
    Yes, my avatar is stolen anonytmouse's Avatar
    Join Date
    Dec 2002
    Posts
    2,544
    Hi, welcome to the forums. The 16 bit wave samples are signed, so you will have to convert them to unsigned. See this post:
    CODE: Retrieving WAVE samples

  3. #3
    Registered User
    Join Date
    Mar 2006
    Posts
    19
    excellent thanks!, didnt see that thread

  4. #4
    Registered User
    Join Date
    Mar 2006
    Posts
    19
    I was hoping somebody could help me out with a quick question are there any functions available to delete sample values from a data chunk in a wave file. I'm not sure you can do this with mmioread or mmiowrite. I was hoping to edit the values inside the data chunk a wave file. I can read and display the sample values but can you use mmiowrite to write over these values or would there be a better/easier way to go about it, any advice is greatly appreciated

  5. #5
    Registered User vinit's Avatar
    Join Date
    Apr 2006
    Location
    India
    Posts
    39
    If u want to replace some bytes then u can use hex editor to edit samples.

  6. #6
    Registered User
    Join Date
    Mar 2006
    Posts
    19
    Is that a seperate program?, unfortunately i'm limited to using C!

  7. #7
    Registered User vinit's Avatar
    Join Date
    Apr 2006
    Location
    India
    Posts
    39
    In that case U've to write code which will include plenty of fseek(); to get to actaul position in file & replace them with new values of ur own.For that use file opening mode as "wb", so that U can replace content at file pointer.U may need to have code like this
    Code:
    struct rec {
     int roll,t;
    };
    rewind(fp);
      while(1) {
    	  if(feof(fp))
    		  break;
    	  fread(&r,sizeof(r),1,fp);
    	  if(r.roll == 2) {
                  if(fseek(fp,-sizeof(r),SEEK_CUR) != 0) 
    		     printf("\nseek error");
    	      r.roll = 99;
    	      fwrite(&r,sizeof(r),1,fp);
    	      break;
    	   }
      }
    U'll notice
    ,-sizeof(r)
    in fseek(); code, -ve offset value allows to go backward in file.As fread(); advances file pointer by specified offset & so file pointer points to next record,so u need to use -ve offset in fseek(); to reach beginning of previous record,in ur case it will be sample i.e. byte.Then u can use fwrite(); to write new value.
    It may damage ur .wav file if u made mistakes during fseek(); & fwrite(); so take backup of it.

  8. #8
    Registered User
    Join Date
    Mar 2006
    Posts
    19
    cheers thanks a million i'll look into that now, i'm only a novice at this sort of thing but it sounds like you've set me on the right track!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Data Structure Eror
    By prominababy in forum C Programming
    Replies: 3
    Last Post: 01-06-2009, 09:35 AM
  2. opening empty file causes access violation
    By trevordunstan in forum C Programming
    Replies: 10
    Last Post: 10-22-2008, 12:19 AM
  3. Formatting a text file...
    By dagorsul in forum C Programming
    Replies: 12
    Last Post: 05-02-2008, 04:53 AM
  4. Unknown Memory Leak in Init() Function
    By CodeHacker in forum Windows Programming
    Replies: 3
    Last Post: 07-09-2004, 10:54 AM
  5. Help open wave file in Borland C++ plz
    By toa2k in forum C++ Programming
    Replies: 1
    Last Post: 01-22-2004, 07:55 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21