How to convert from long to short ?

L

LaMoRt

Hi
I want to ask how to convert from long to short since i have some
parameter problem with it?
The problem is like below :

short *speech; // Holds length of any given sample

* speech = pMediaSample->GetActualDataLength();

va_g729a_encoder(short *speech, unsigned char *bitstream );

The Calling GetActualDataLength() is in the long declaration and i have
to change it
to short since calling the speech parameter is in short.
The encoder calling part is default and cannot change the short speech
parameter.
So how should resolve it .
Thanks for the help.
 
M

Malcolm

LaMoRt said:
I want to ask how to convert from long to short since i have some
parameter problem with it?
The problem is like below :

short *speech; // Holds length of any given sample

* speech = pMediaSample->GetActualDataLength();

va_g729a_encoder(short *speech, unsigned char *bitstream );

The Calling GetActualDataLength() is in the long declaration and i have
to change it
to short since calling the speech parameter is in short.
The encoder calling part is default and cannot change the short speech
parameter.
So how should resolve it .
Thanks for the help.
To convert a long to a short, simply write

short st;
long lg = 3;

st = (short) lg;

However i suspect that you don't understand how to use pointers. Why is
"speech" a pointer, and what does it point to? Why is "speech" not a short,
if it holds the sample length.

I am not familiar with your call, but I also doubt that the sample length
(nmuber of samples) would be stored in a short - why limit it to 16 bits?
The samples themselves, however, might well be shorts. CDs and many other
systems use 16-bit samples.
 
S

Simon Biber

LaMoRt said:
Hi
I want to ask how to convert from long to short since i have some
parameter problem with it?
The problem is like below :

short *speech; // Holds length of any given sample

This is a pointer that has not been initialised. It may point to a
random location in memory. It is undefined behaviour to try to
dereference a pointer before it is set to point to a valid location in
memory.
* speech = pMediaSample->GetActualDataLength();

Here, you attempt to dereference the uninitialised pointer 'speech',
which is undefined behaviour.
va_g729a_encoder(short *speech, unsigned char *bitstream );

The Calling GetActualDataLength() is in the long declaration and i have
to change it
to short since calling the speech parameter is in short.
The encoder calling part is default and cannot change the short speech
parameter.
So how should resolve it .
Thanks for the help.

How about something like:

short speech;
speech = pMediaSample->GetActualDataLength();
va_g729a_encoder(&speech, bitstream);
 
L

LaMoRt

Thanks for the reply.
Actually I am not really good at pointer and it is in 16 bit beacuse
the G.729 codec need it in 16 bit.Actually i am trying to integrate to
our encoder so we just have to call the function that are available on
the API since it have a library that we could include.
The short *speech is pointed to another header file.
* speech = pMediaSample->GetActualDataLength();
i want to pass the actual data length to speech and use it as a
parameter to another function which is
va_g729a_encoder(short *speech, unsigned char *bitstream );

the GetActualDataLength is initialize as long, and we need to follow
the va_g729a_encoder function as it is an API and the speech parameter
is in short.
so how should i convert long to short?
 
C

Christian Bau

"LaMoRt said:
Hi
I want to ask how to convert from long to short since i have some
parameter problem with it?
The problem is like below :

short *speech; // Holds length of any given sample

* speech = pMediaSample->GetActualDataLength();

va_g729a_encoder(short *speech, unsigned char *bitstream );

The Calling GetActualDataLength() is in the long declaration and i have
to change it
to short since calling the speech parameter is in short.
The encoder calling part is default and cannot change the short speech
parameter.
So how should resolve it .
Thanks for the help.

If I were you, I would very very _very_ carefully check the
documentation of the function va_g729a_encoder. Since the number of
bytes needed to store 0.2 seconds of CD quality sound is already too
large to be stored into a short portably, there seems to be something
wrong here.
 
K

Keith Thompson

Malcolm said:
To convert a long to a short, simply write

short st;
long lg = 3;

st = (short) lg;

Or, even more simply:

short st;
long lg = 3;

st = lg;
 
C

Chris Hills

Keith Thompson <kst- said:
Or, even more simply:

short st;
long lg = 3;

st = lg;

Thanks....

I was just updating the Arianne 6 navigation system.... :)
 
L

LaMoRt

Thanks all , i got it already ...
I will check it properly for the documents.
U all give me a good help, thanks so much.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,172
Messages
2,570,934
Members
47,477
Latest member
ColumbusMa

Latest Threads

Top