Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > How to convert from long to short ?

Reply
Thread Tools

How to convert from long to short ?

 
 
LaMoRt
Guest
Posts: n/a
 
      01-02-2006
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.

 
Reply With Quote
 
 
 
 
Malcolm
Guest
Posts: n/a
 
      01-02-2006

"LaMoRt" <(E-Mail Removed)> 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.


 
Reply With Quote
 
 
 
 
Simon Biber
Guest
Posts: n/a
 
      01-02-2006
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.
 
Reply With Quote
 
LaMoRt
Guest
Posts: n/a
 
      01-02-2006
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?

 
Reply With Quote
 
Christian Bau
Guest
Posts: n/a
 
      01-02-2006
In article <(E-Mail Removed). com>,
"LaMoRt" <(E-Mail Removed)> 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.
 
Reply With Quote
 
Keith Thompson
Guest
Posts: n/a
 
      01-02-2006
"Malcolm" <(E-Mail Removed)> 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) http://www.velocityreviews.com/forums/(E-Mail Removed) <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.
 
Reply With Quote
 
Chris Hills
Guest
Posts: n/a
 
      01-02-2006
In article <(E-Mail Removed)>, Keith Thompson <kst-
(E-Mail Removed)> writes
>"Malcolm" <(E-Mail Removed)> 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 /\/\/\/\/
/\/\/ (E-Mail Removed) www.phaedsys.org \/\/\
\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/



 
Reply With Quote
 
LaMoRt
Guest
Posts: n/a
 
      01-03-2006
Thanks all , i got it already ...
I will check it properly for the documents.
U all give me a good help, thanks so much.

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: How include a large array? Edward A. Falk C Programming 1 04-04-2013 08:07 PM
Having compilation error: no match for call to (const __gnu_cxx::hash<long long int>) (const long long int&) veryhotsausage C++ 1 07-04-2008 05:41 PM
unsigned short, short literals Ioannis Vranos C Programming 5 03-05-2008 01:25 AM
longs, long longs, short short long ints . . . huh?! David Geering C Programming 15 01-11-2007 09:39 PM
unsigned short short? slougheed@gmail.com C++ 4 10-16-2006 11:25 PM



Advertisments