Allegro.cc - Online Community

Allegro.cc Forums » Programming Questions » Audio Streams in C++

Credits go to miran for helping out!
This thread is locked; no one can reply to it. rss feed Print
Audio Streams in C++
James Stanley
Member #7,275
May 2006
avatar

I posted a question about audio streams once before. I subsequently found out that the reason my code wasn't compiling was because I was using C++ and not C. The type exchanging stuff (IMHO) is better in C. Now, how would I go about doing audio streams in C++? Any thoughts?

Evert
Member #794
November 2000
avatar

Quote:

the reason my code wasn't compiling was because I was using C++ and not C. The type exchanging stuff (IMHO) is better in C. Now, how would I go about doing audio streams in C++?

Post source.

miran
Member #2,407
June 2002

AUDIOSTREAM *stream;
...
stream = play_audio_stream(BUFFER_SIZE, 8, FALSE, SAMPLING_FREQUENCY, 255, 128);
...
...
unsigned char *buffer = (unsigned char *)get_audio_stream_buffer(stream);
...

if you use 8 bit sound and

AUDIOSTREAM *stream;
...
stream = play_audio_stream(BUFFER_SIZE, 16, FALSE, SAMPLING_FREQUENCY, 255, 128);
...
...
unsigned short *buffer = (unsigned short *)get_audio_stream_buffer(stream);
...

if you use 16 bit sound.

--
sig used to be here

James Stanley
Member #7,275
May 2006
avatar

Evert, I really don't think that's necessary as I hardly have any and I'm just looking for the framework.

EDIT:
Thank you, miran!

Evert
Member #794
November 2000
avatar

If your source is giving you problems `because you're using C++, not C', then you should post said source so that we can say what you should change or add to make it work. Otherwise it wouldn't be really useful to post random thoughts about it, would it? ;)

miran
Member #2,407
June 2002

Btw, "the type exchanging stuff" is called typecasting or casting for short. C is a weakly typed language (not really, but that's not the point), because when you have void* it means you have a pointer to anything. C++ on the other hand is strongly typed which means that void* shouldn't even be valid code (it's valid as a special case for backwards compatibility with C). In C++ when you have a pointer to something (void* is like a pointer to nothing in C++) and want to use it as if it was a pointer to something else, you need to cast it to that something else type. For your needs (using a C library that uses void pointers in C++) a simple C-style cast is good enough. A C style cast is when you write the type you want to cast to in front of the variable you want to cast in parenthesis. For example to cast a variable called x of type float to type int, you would write (int)x, and when you want to cast a variable called buffer of type void* to type int*, you type (int*)buffer.

--
sig used to be here

Steve++
Member #1,816
January 2002

(never mind (grumble, grumble))

James Stanley
Member #7,275
May 2006
avatar

So what's C++ typecasting like?
EDIT: Oh, wait. What you showed me is C++ typecasting, yeah?

Steve++
Member #1,816
January 2002

Go to: