473,385 Members | 1,610 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

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.

Jan 2 '06 #1
7 13302

"LaMoRt" <cw****@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.
Jan 2 '06 #2
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.
Jan 2 '06 #3
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?

Jan 2 '06 #4
In article <11*********************@g43g2000cwa.googlegroups. com>,
"LaMoRt" <cw****@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.
Jan 2 '06 #5
"Malcolm" <re*******@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) ks***@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.
Jan 2 '06 #6
In article <ln************@nuthaus.mib.org>, Keith Thompson <kst-
u@mib.org> writes
"Malcolm" <re*******@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 /\/\/\/\/
/\/\/ ch***@phaedsys.org www.phaedsys.org \/\/\
\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/

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

Jan 3 '06 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: jose luis fernandez diaz | last post by:
Hi, The program below prints a unsigned short in binary base: #include <iostream> int main() { unsigned short mask =0x1; unsigned short us =0x0071;
6
by: ~toki | last post by:
I'm triyng to use this function int result = NativeMethods.midiOutGetDevCaps( -1, ref pSI, (uint)Marshal.SizeOf(pSI) ); Docs say that pSI is a struct (below) typedef struct { WORD wMid;...
3
by: MuZZy | last post by:
Hi, I just wonder if someone can help me wit this - i have a byte array and need to convert it to short array, creating short numbers by combining bytes by pairs: My array: byte, byte, byte,...
12
by: Wolfgang Kaml | last post by:
Dear all, I am using the following code to retrieve the size of a certain file and the available (free) space on the disk. The problem is, that I get the size of the file returned as a Long and...
3
by: Eric BOUXIROT | last post by:
hi, i must convert all of these eVC++ prototypes to use with VB.NET.... DLLEXPORT long F_BDO_MessageBoxOK(char *IN_title, char *IN_msg ); DLLEXPORT long F_BDO_MessageBoxOUINON(char *IN_title,...
65
by: kyle.tk | last post by:
I am trying to write a function to convert an ipv4 address that is held in the string char *ip to its long value equivalent. Here is what I have right now, but I can't seem to get it to work. ...
24
by: cedarson | last post by:
I am having trouble writing a simple code that will convert an int ( 487 for example ) to binary form just for the sake of printing the binary. Can someone please help? Thanks!
28
by: Fore | last post by:
Hello I am looking for some effecient way to convert a 32 bit unsigned integer to a 16 bit signed integer. All I want is the lower 16 bits of the 32 bit unsigned integer , with bit 15 (0..15) to...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.