Archived

This topic is now archived and is closed to further replies.

[Windows] Using the waveOut API, how to play files of different sampling rates?

This topic is 6011 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Here is my problem. I initialize the waveOut API with a sampling rate of 44100 so thatI can play CD-quality audio, but when I try to play any .WAV file that has a sampling rate of 22050 (most built-in windows sounds), the file plays twice as fast. I know that this is suppoised to happen but my question is how can I play files with any sampling rate if I initialize the API with 44100? I am doing streaming and non-streaming audio under Windows. I want my streams to be at 44100 but the other files I play can be encoded at less that that. Is this possible? Regards, Kinfira Lead Programmer KinfiraSoft Makers of Swordplay, a 3D fighting game engine. Check out our home on the web: http://www.kinfirasoft.com

Share this post


Link to post
Share on other sites
What you can do:

When reading the wave file into memory, determine the sampling rate before you begin streaming.

Based on the sampling rate, you can still play at 44.1k, but just make sure to send a correct ratio of data to trick it into thinking its playing 44.1k.

Share this post


Link to post
Share on other sites
Hm, suggesting interpolating for this solution--dunno about that. For 22.05kHz, you gotta come up with one sample per sample, obviously. You could do linear interpolation, or hold (repeat same value twice, make it look like a step); I don''t know what these would sound like, the human ear is amazingly good at detecting some things. However, what do you do with 16kHz and 8kHz files?

Is closing & reopening the sound device completely out of the question?

Share this post


Link to post
Share on other sites
Sorry about the lateness of my reply.

quote:
Stoffel said:
However, what do you do with 16kHz and 8kHz files?

At the moment, they will also not play correctly.

quote:

Is closing & reopening the sound device completely out of the question?


The main idea behind all this is that I want to play streamed background music at 44100kHz but some of my sound effects may be encoded at a lower sampling rate. I can''t close and reopen the sound device without terminating the already playing music. One solution would be to require all music and sound be encoded at 44100kHz but I was hoping to avoid that.

quote:
Nytegard said:
What you can do:

When reading the wave file into memory, determine the sampling rate before you begin streaming.

Based on the sampling rate, you can still play at 44.1k, but just make sure to send a correct ratio of data to trick it into thinking its playing 44.1k.


Any idea on how to make it do this? Do I simply need to mangle the sound data somehow? BTW I am doing this currently with uncompressed PCM data.

Thank for the help given so far.



Regards,

Kinfira
Lead Programmer
KinfiraSoft
Makers of Swordplay, a 3D fighting game engine.

Check out our home on the web:
http://www.kinfirasoft.com

Share this post


Link to post
Share on other sites
I''m a little out of my depths here since I only work with single data streams with the sound card, but I think you need to talk to the mixer to do that. There should be a separate audio path for CD audio to the sound card output--I think you use MCI for this? Again, I don''t have any experience here, so maybe somebody more knowledgable should step in--just didn''t want to see this topic die without answering this guy''s question.

Share this post


Link to post
Share on other sites