•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the C section within the Software Development category of DaniWeb, a massive community of 428,381 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 3,608 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our C advertiser: Programming Forums
Views: 856 | Replies: 4 | Solved
![]() |
•
•
Join Date: Jun 2008
Posts: 3
Reputation:
Rep Power: 0
Solved Threads: 0
Hi all,
I'm a newbie with C or C++. I have a raw PCM file 16-bit (like a wav file but no header). I need to build a console application that can read the file, store data in an array, modify it (ex: add 100 to each value of the data array), then play it in sound (with a known frequency sampling, ex Fs = 16000 Hz).
It would be very nice if someone can explain to me how to do that.
Thank you very much.
I'm a newbie with C or C++. I have a raw PCM file 16-bit (like a wav file but no header). I need to build a console application that can read the file, store data in an array, modify it (ex: add 100 to each value of the data array), then play it in sound (with a known frequency sampling, ex Fs = 16000 Hz).
It would be very nice if someone can explain to me how to do that.
Thank you very much.
Sure, which bit exactly are you having problems with?
- reading into an array
- adding values
- playing it
- reading into an array
- adding values
- playing it
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
Do not PM me for help; You'll be ignored, or told to learn to read.
Do not ask me if I'm muslim - I'm not. Nor do I care about yours or anyone else's mysticism. Religion is a matrix, take the RED PILL.
Do not PM me for help; You'll be ignored, or told to learn to read.
Do not ask me if I'm muslim - I'm not. Nor do I care about yours or anyone else's mysticism. Religion is a matrix, take the RED PILL.
•
•
Join Date: Jun 2008
Posts: 3
Reputation:
Rep Power: 0
Solved Threads: 0
•
•
•
•
Sure, which bit exactly are you having problems with?
- reading into an array
- adding values
- playing it
Thks for your answer
Here is my code of reading values into an array
cplusplus Syntax (Toggle Plain Text)
#include <iostream> #include <fstream> using namespace std; void main() { std::fstream f_in; short speech, value[10000]; f_in.open ("myfile.pcm", std::ios::in | std::ios::binary); int i = 0; while (i < 10000) { f_in.read((char *)&speech, 2); value[i] = speech; cout << speech << std::endl; i++; } }
The problem is how to play sound from value array, with frequency sampling Fs = 16000hz.
Thks for any advice
Last edited by Ancient Dragon : Jun 9th, 2008 at 6:16 pm. Reason: add code tags
•
•
Join Date: Aug 2005
Location: near St Louis, Missouri, USA
Posts: 11,229
Reputation:
Rep Power: 38
Solved Threads: 937
I can't help you with your problem, but you don't need that while loop
But of course there is no guarentee that sizeof(short) will be 2. It might be on your system but if you intend to port that porgram to another os then the size may be something else.
f_in.read(speech, 10000 * sizeof(short));
But of course there is no guarentee that sizeof(short) will be 2. It might be on your system but if you intend to port that porgram to another os then the size may be something else.
I think it's about time we voted for senators with breasts. After all, we've been voting for boobs long enough. ~Clarie Sargent, Arizona senatorial candidate
Those who are too smart to engage in politics are punished by being governed by those who are dumber. ~Plato
Those who are too smart to engage in politics are punished by being governed by those who are dumber. ~Plato
•
•
Join Date: Jun 2008
Posts: 3
Reputation:
Rep Power: 0
Solved Threads: 0
Thks for all of you.
I found my answer here:
http://www.insomniavisions.com/docum...rials/wave.php
Thks
I found my answer here:
http://www.insomniavisions.com/docum...rials/wave.php
Thks
![]() |
•
•
•
•
•
•
•
•
DaniWeb C Marketplace
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
Other Threads in the C Forum
- Previous Thread: Http/ Https request from C
- Next Thread: Status bar



Linear Mode