Thread: Speech Analysis

  1. #16
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    Even if the data can be said to be "close", but we need something to know what kind of values are the right one's, once we get them, out of the file.

    Or, at least I do!

  2. #17
    Registered User
    Join Date
    Jun 2010
    Posts
    16
    thanks for sticking with me here... this is a simple question but its because fread is very new to me... how to i only read in one byte then?

    Code:
     fread(&clip_info[k],1,6000,file_in);
    if thats the change i need to make.. it does nothing...

    makeing the variable a short instead of int.. changes the numbers dramatically but i would like to see what reading in one value at a time will do..

    i had no luck find any other examples of extracted data from a wave file online..

  3. #18
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    fread() reads in size * NumberOf bytes:

    fread(bufferArrayName, Size, NumberOf, FilePointer);

    smart to take it one value at a time, I suspect.
    Last edited by Adak; 06-10-2010 at 01:12 AM.

  4. #19
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    Is this file a WAV file with raw PCM data?

    I found this tidbit interesting:

    BhupathiRao

    hai everyone; I am reading 'time001.wav' sound file by using wavread function. But it gives the amplitude values between [-1 to +1]. How can i read amplitude values more than the [-1 to +1].
    More options Apr 24, 5:03 am
    Newsgroups: comp.soft-sys.matlab
    From: "BhupathiRao " <[email protected]>
    Date: Sat, 24 Apr 2010 09:03:04 +0000 (UTC)
    Local: Sat, Apr 24 2010 5:03 am

    Subject: how to read amplitude out of range in my wav file

    hai everyone;

    I am reading 'time001.wav' sound file by using wavread function. But it gives the amplitude values between [-1 to +1]. How can i read amplitude values more than the [-1 to +1].

    Rune Allnor

    More options Apr 24, 6:46 am
    Newsgroups: comp.soft-sys.matlab
    From: Rune Allnor <[email protected]>
    Date: Sat, 24 Apr 2010 03:46:57 -0700 (PDT)
    Local: Sat, Apr 24 2010 6:46 am

    Subject: Re: how to read amplitude out of range in my wav file

    On 24 apr, 11:03, "BhupathiRao " <[email protected]> wrote:

    > hai everyone;

    > I am reading 'time001.wav' sound file by using wavread function. But it gives the amplitude values between [-1 to +1]. How can i read amplitude values more than the [-1 to +1].

    As I understand it, the contents of the .wav file is normalized
    to the [-1,1] interval. If correct, it means that you can not read
    values outside that interval.

    Rune

    Wayne King
    More options Apr 24, 6:58 am
    Newsgroups: comp.soft-sys.matlab
    From: "Wayne King" <[email protected]>
    Date: Sat, 24 Apr 2010 10:58:06 +0000 (UTC)
    Local: Sat, Apr 24 2010 6:58 am

    Subject: Re: how to read amplitude out of range in my wav file

    "BhupathiRao " <[email protected]> wrote in message <[email protected]>...
    > hai everyone;

    > I am reading 'time001.wav' sound file by using wavread function. But it gives the amplitude values between [-1 to +1]. How can i read amplitude values more than the [-1 to +1].

    Hi, if the data are represented by 32 bits or less in the wave file and you read the file with the default 'double' format, the data range is always [-1,1]. If you read the data as 'native' you will get a range depending on the number of bits.

    At any rate, I think you will have to scale the result in Matlab to get a signal with values outside of [-1,1].

    If you created the file by sampling audio and you know the voltage input range at the A/D converter, say [-5,5] volts. Then you can read the file using 'native' and use the quantization step to convert the values to volts in the Matlab command window.

    Wayne

    Forward


    So are we looking for a -1, 1 range or -5, 5, or ??
    Last edited by Adak; 06-10-2010 at 01:29 AM.

  5. #20
    Registered User
    Join Date
    Jan 2009
    Posts
    1,485
    Okey, this reads in one sample at a time, but, I would choose to use short. I stop by three times before I reach the sound buffer and get info from the header at offsets found on the internet.

    Code:
    #include <stdio.h>
    
    #define FILENAME "omega.wav"
    #define SRATE_OFFSET 24
    #define BITS_OFFSET 34
    #define SIZE_OFFSET 40
    
    
    int main(void)
    {
            int x;
            short clip_info[10000];
            int sampleRate, bitDepth, dataSize;
            FILE * file_in;
    
    
            file_in = fopen(FILENAME,"r");
    
            if (file_in == NULL)
            {
                    printf("Error Opening file.");
            }
            else
            {
                    printf("success\n");
                    fseek(file_in, SRATE_OFFSET, SEEK_SET);
                    fread(&sampleRate, 4, 1, file_in);
    
                    fseek(file_in, BITS_OFFSET, SEEK_SET);
                    fread(&bitDepth, 2, 1, file_in);
    
                    fseek(file_in, SIZE_OFFSET, SEEK_SET);
                    fread(&dataSize, 4, 1, file_in);
    
                    fread(clip_info, 10000, 1, file_in);
            }
    
                    for (x=0; x<= 5000; x++)
                            printf("% d\n", clip_info[x]);
    
                    printf("Sample rate: %d\n", sampleRate);
                    printf("Bit depth: %d\n", bitDepth);
                    printf("Sound data size: %d\n", dataSize);
    
            return 0;
    }
    BTW, no error checking and so going on here.
    Last edited by Subsonics; 06-10-2010 at 03:29 PM. Reason: Made changes to short data type

  6. #21
    Registered User
    Join Date
    Jan 2009
    Posts
    1,485
    Adak, they are discussing what is returned from a wavfile read function. Normally audio data is processed as floats to avoid loosing precision as well as avoid clipping and are only converted back to integers before entering a file or a converter.

  7. #22
    Registered User
    Join Date
    Jun 2010
    Posts
    16
    Hey sorry for the late response, ended up falling asleep! ha

    anyways I've changed my source code to what you put there and so far its working great for extracting the data out of the header .. it says

    Sample rate: 22050
    Bit depth: 16
    Sound data size: 291939


    however the actual "Data" chunk is a series of around 5000 zeros haha .. so since the data size is 291939 I changed the array to be 60000 bits large and to have its values filled... i now get a few numbers.. i will show you the sample data from the companion website that goes with my book... its file is "ZERO.txt"
    the file im generating is title "Data.txt" the wave file is PCM data.

    i changed the values to short the previous Data.txt

    but im thinking that something wierd is going on still...

    thanks for sticking with me on this one

  8. #23
    Registered User
    Join Date
    Jan 2009
    Posts
    1,485
    Yeah, that doesn't look right. It looks right here, but I use a different sound file. Did you get rid of the loop in fread? I made some edits to the above code to reflect what I did here.

    Other issues could be that there is no error checking, for the reads which should be in there to confirm that the data is read successfully before printing etc. Or, that you are using a non standard wav but a broadcast wav, they have a large meta data chunk in the header. Since you recorded this yourself you can confirm that with the the program you did the recording in.

    Later on you would probably also want to use malloc to allocate memory for the sound.


    Edit: BTW, do you print to screen or do you write it to your text file only? The problem could be when you are writing it back to the text file as well, if you are not redirecting the output to a file in a terminal.
    Last edited by Subsonics; 06-10-2010 at 01:04 PM.

  9. #24
    Registered User
    Join Date
    Jun 2010
    Posts
    16
    hey thank you,
    I have been writing it to a text file.

    I just tried useing the edited source code and for whatever reason it does not like reading my wave file now.. i get Access violation writing location 0x001b9a1e.

  10. #25
    Registered User
    Join Date
    Jun 2010
    Posts
    16
    nm i just solved that part ... fread(&clip_info[k], 10000, 1, file_in);

    had to remove [k] haha so now its looking better i get a file as follows

  11. #26
    Registered User
    Join Date
    Jun 2010
    Posts
    16
    Now when i try getting this data into exponent form it makes every value exactly the same.. what are my options here.. i suppose i have to write it in as a long int.. but that defeats what we were trying to solve by creating a short int..

    also how can i confirm if the data it reading is correct if i have
    Sample rate: 22050
    Bit depth: 16
    Sound data size: 291939
    can i calculate how long the sample should be in seconds.. and check it with actual time... because as it stands ive created two seperate wave files and when i read each of them in i get a sound data size of 291939 for both.. and they are different lengths

  12. #27
    Registered User
    Join Date
    Jan 2009
    Posts
    1,485
    Quote Originally Posted by rambo5330 View Post
    nm i just solved that part ... fread(&clip_info[k], 10000, 1, file_in);

    had to remove [k] haha so now its looking better i get a file as follows
    Yeah and the ampersand, I just edited it here, no copy paste. Missed that part.

  13. #28
    Registered User
    Join Date
    Jan 2009
    Posts
    1,485
    Quote Originally Posted by rambo5330 View Post
    Now when i try getting this data into exponent form it makes every value exactly the same.. what are my options here.. i suppose i have to write it in as a long int.. but that defeats what we were trying to solve by creating a short int..
    You need floating point variables to print in exponent form with printf. Not ints or shorts.

    I doesn't defeat the purpose of reading it into a buffer with short ints. The reason for that is that the data is just read to the address of clip_info and forward in a continuos fashion. No regards what so ever is taken on the data type of clip_info. It's to simplify getting the data into a buffer where each element match in size.

    You can read it into ints and loop through the buffer, but you will lose the signed bit, since the most significant bit of a short, is not at the same place as the MSB of an int, the size don't match.

    Quote Originally Posted by rambo5330 View Post
    also how can i confirm if the data it reading is correct if i have
    Sample rate: 22050
    Bit depth: 16
    Sound data size: 291939
    can i calculate how long the sample should be in seconds.. and check it with actual time... because as it stands ive created two seperate wave files and when i read each of them in i get a sound data size of 291939 for both.. and they are different lengths
    Well, write it back to a new file and try to play it! Note you'll then need a header obviously. Or, easier confirm it by compare it with a hexdump of your original file, let's say the first 100 bytes or so like this if you got unix :

    Code:
    xxd -seek 44 -l 100 omega.wav

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Beam or Frame Analysis for Structural Analysis
    By greenmania in forum C Programming
    Replies: 3
    Last Post: 05-05-2010, 05:40 PM
  2. Using MS Speech in BCPPB 6.0
    By MiraX33 in forum Windows Programming
    Replies: 0
    Last Post: 02-26-2006, 10:21 AM
  3. Dev-C++ Profile Analysis
    By Orborde in forum C++ Programming
    Replies: 0
    Last Post: 05-28-2005, 01:37 AM
  4. Speech coding, detecting pitch
    By subdene in forum C++ Programming
    Replies: 2
    Last Post: 11-24-2004, 09:35 PM
  5. rhetorical analysis and why it is for YOU!
    By doubleanti in forum A Brief History of Cprogramming.com
    Replies: 2
    Last Post: 03-30-2003, 02:11 PM