Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   C Programming (http://www.velocityreviews.com/forums/f42-c-programming.html)
-   -   How to convert from long to short ? (http://www.velocityreviews.com/forums/t440727-how-to-convert-from-long-to-short.html)

LaMoRt 01-02-2006 06:32 AM

How to convert from long to short ?
 
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.


Malcolm 01-02-2006 06:39 AM

Re: How to convert from long to short ?
 

"LaMoRt" <cwei83@gmail.com> wrote
> 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.



Simon Biber 01-02-2006 07:29 AM

Re: How to convert from long to short ?
 
LaMoRt wrote:
> 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);

--
Simon.

LaMoRt 01-02-2006 08:25 AM

Re: How to convert from long to short ?
 
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?


Christian Bau 01-02-2006 09:36 AM

Re: How to convert from long to short ?
 
In article <1136183549.311300.81450@g43g2000cwa.googlegroups. com>,
"LaMoRt" <cwei83@gmail.com> wrote:

> 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.

Keith Thompson 01-02-2006 10:30 AM

Re: How to convert from long to short ?
 
"Malcolm" <regniztar@btinternet.com> writes:
[...]
> 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;

--
Keith Thompson (The_Other_Keith) kst-u@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.

Chris Hills 01-02-2006 01:32 PM

Re: How to convert from long to short ?
 
In article <lnhd8mhqgr.fsf@nuthaus.mib.org>, Keith Thompson <kst-
u@mib.org> writes
>"Malcolm" <regniztar@btinternet.com> writes:
>[...]
>> 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;
>


Thanks....

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


--
\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\
\/\/\/\/\ Chris Hills Staffs England /\/\/\/\/
/\/\/ chris@phaedsys.org www.phaedsys.org \/\/\
\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/




LaMoRt 01-03-2006 09:11 AM

Re: How to convert from long to short ?
 
Thanks all , i got it already ...
I will check it properly for the documents.
U all give me a good help, thanks so much.



All times are GMT. The time now is 03:58 PM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.