How to create short from byte[2]

Hi, my problem is, that once i wrote application which was able to add echo to a wav file in c++ :
#include<iostream>
#include<string>
#include<cstdio>
using namespace std;
int write=0;
int read=0;
void insert(short int * tablica,short int element,int value);
void read_out(short int * liczba,short int * tablica,int value);
int main(){
FILE * file_in;
FILE * file_out;
char header[44];
file_in = fopen("output.wav","rb");
cout<<"wprowadz dlugosc echa: "<<endl;
int echo;
int count=0;
cin>>echo;
short int * fifo=new short int[echo];
short int sample;
short int temp;
file_out = fopen("new.wav","wb");
fread(header,44,1,file_in);
fwrite(header,44,1,file_out);
for(int p=0;p<echo-2;p++)
insert(fifo,0,echo);
while(fread(&sample,2,1,file_in))
read_out(&temp,fifo,echo);
temp = temp/3 + sample/2;
insert(fifo,temp,echo);
fwrite(&temp,2,1,file_out);
fclose(file_out);
fclose(file_in);
delete fifo;
return 0;
void insert(short int * tablica,short int element,int value)
tablica[write%value]=element;
write++;
void read_out(short int * liczba,short int * tablica,int value)
(*liczba)=tablica[read%value];
read++;
}as You see above it's very simple, and I wrote it ages ago, and now I need to prepare a presentation for a JUG meeting, and it's gonna be about all java support for different kinds of sound. That's why I wanna write application to manipulate some sort of sound files ( in this case a .wav file).
My problem is that when I repeat this code in Java it works differently. first problem, is that I read samples form wav using FileInputStreamReader, and it reads either bytes or ints , and I need to read shorts, cause it's 16bit wav file. So I'm reading via FileInputStreamReader every 2 bytes, and trying to convert it to short using bit shifts, but it never works. Does anyone knows how to read stream to short type, or how to convert bytes[2] to short safely? Thanks in advance.

I was having a very similar problem converting a byte array to a double array. Please see this thread:
http://forums.sun.com/thread.jspa?threadID=5438070&tstart=0
The method suggested by captfoss in that thread and in this thread should work, but it doesn't seem to work correctly. Instead, I had to handle each bit on an individual basis to get the correct result, like this:
                                int d = 0;
                                for (int j = 0; j < 8; j++) {
                                    if (((data[2*i] >>> j) & 1) == 1) {
                                        d += (int) Math.pow(2, j);
                                for (int j = 0; j < 7; j++) {
                                    if (((data[2*i+1] >>> j) & 1) == 1) {
                                        d += (int) Math.pow(2, j+8);
                                if (((data[2*i+1] >>> 7) & 1) == 1) {
                                    d -= Math.pow(2, 15);
                                wave.get(lastD) = d;
wave is a double array, so it casts d to a double in the last line.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

Similar Messages

  • How to create RSAPublicKeySpec from byte[]

    Hi,
    another question: i've the public key encoded in ascii format on disk. How can i create the RSAPublicKeySpec from that byte[] array? i don't have the modulus and exponent...
    thanks
    Luca

    Take a look at java.security.KeyFactory.generatePublic(KeySpec) and java.security.spec.X509EncodedKeySpec.
    Grant

  • How to create database from .sql file

    how to create database from .sql file..?? i put the sintax query in a sql file.. and i want to call it in java code..
    ho to do it..??

    why do you want to do this from java?
    i just don't see the point.
    find your dba and have him/her run it for you

  • How to create data_block from procedure ?

    hi all
    can anyone to help me :
    how to create data_block from procedure ?
    i want to join 2 or 3 table and use order by
    then show some field in my form
    i can not use view because order by can not use in view
    please send sample code for this procedure
    thanks.

    1) >i can not use view because order by can not use in view
    SQL>create or replace view V_test as
      2  select * from (
      3  select 1 id from dual union
      4  select 2 id from dual union
      5  select 3 id from dual union
      6  select 4 id from dual union
      7  select 5 id from dual union
      8  select 6 id from dual ) t
      9  order by t.id
    10  /
    View created.
    SQL>select * from v_test;
            ID
             1
             2
             3
             4
             5
             6
    6 rows selected.2). >how to create data_block from procedure?
    You must create procedure and use ref cursor.

  • How to create report from report painter??

    Hi,
    how to create report from report painter?? from transaction code GRR1

    Select the library that you want report to create.  GRR1
    You select what to list in coulumns and what to lisr in rows. You could select characteristics or key figures.
    You can use variable both in defininig row and coulmn or in general selection.
    You can also use sets as variable or as constant. These sets can be your master data groups or sets in GS02.
    You can use formulas.

  • How to create Short Lived process?..can neone pls help...

    How to create Short Lived process?..can neone pls help...

    Hi,
    Login into workbench. Click on Help->Workbench start page.
    Lot of helps are there you can go through them. They will be helpful.
    But it seems you are new to livecycle, so it will difficult to start through help. Either you can take help of any of your team member who is expert in livecycle or some training you should attend.
    Thanks

  • How to Create PDF from Illustrator CS3 by using applescript?

    Hi Guys,
    Do some one knows how to create PDF from Illustrator CS3 by using apple script. If know, please give me the scripting.
    HARI

    Have you tried File>Scripts>SaveDocsAsPDF? There should be a folder of sample scripts installed in your AICS3 folder and a folder of documentation which contains an Illustrator AppleScript Reference which has examples.

  • How to create "convert from PDF to Word?"

    How to create "convert from PDF to Word?"

    Good day,
    To use the ExportPDF service, simply visit http://exportpdf.acrobat.com and click 'Sign in' at the top right corner.  Enter your Adobe ID (email address) credentials to log into the service.  As ExportPDF is web-based, you simply utilize the tool through your web browser.  After you're logged in, you should see the ExportPDF interface, with a button saying 'Select PDF file..' to get the process started.
    Please let us know if you have any questions.
    Kind regards,
    David

  • How to create Analysis from two different subject areas with diff models

    Hello,
    I have problem with create analysis from two different areas with two different models (Model Star and Snowflakes) build in BI Admin tools.
    First Model A = Subject Area A have one fact tables (with measures) and three dimensions tables (Model Star)
    Second Model B = Subject Area B have one fact table (no measures) and five dimensions tables (Model Snowflakes).
    I'm looking solutions how I can give good results. In this case I can't use UNION, INTERSECT etc., because this models haven't the same number column and data type?
    whether it is possible to do in OBIEE?
    Please help me
    Kind regard
    robix

    Hi
    One thing to understand is that if your are imagining having two Subject Areas (SAs) displayed and then dragging columns from each into your Request without any preparation, then no, that can't be done. You would need to do a join in the BMM layer and expose the column from the second Subject Area in the presentation layer.
    But if you indeed interested in UNION (or intersect) queries, then do this:
    Build your first query in the first SA in the usual manner. Note the number of columns and the data types of each column.
    Now at the bottom of the Criteria workspace, there is a button called "Combine with similar request." Click it.
    Select your second SA. You will note that the outlines of the columns in your first query appear. This is to remind you that the number of columns in this second query must be the same as in the first. It also shows the data type of each column for the same reason.
    Once you select your columns and your filters, click on result. (Oh, you will also need to decide what kind of combination you want -- click on the dropdown.) The result will be a new Request that has data from both SAs in the query and combined in the manner you select (union, intersect, etc.)
    That should give you a start.
    http://obiee101.blogspot.in/2010/08/obiee-combine-with-similar-request.html -- Read this link this is good one to understand with screen shots. -- OBIEE 10g
    http://oraclebiee11g.blogspot.in/2011/01/querying-across-multiple-subject-areas.html -- OBIEE 11g
    Award Points it is useful.
    Thanks
    satya

  • How to create reports from my existing web application on Java/J2EE with Oracle Client 10g as the backend?? Help sought for

    Our company has developed an  Web Application and we are also looking out for the development of reports using Business Objects Exterprise XI Release 2 and for this purporse I do require some help from the forum who can literally show me how to get on and working on creating the reports.

    Thats why I thought I should make the following chain in the keystore, possibly in this order.
    1. My private key (simply generated in the server)
    2. Import Root certificates from NS
    3. Import Trusted certificate issued by NS
    Then when I sign with my private key surely an association will be formed to the trusted authority certificate. The problem I'm having is when I first made my private key I used openSSL as it was only intended for HTTPS. Now I need to create a keystore so I can use jarsigner to sign the jar file, and I can't see how to create a keystore using my existing private key. Surely if I created a new key and self sign, then import the trusted certificate the association will fail, as the private key will not be the same 1 that I used to make the CSR when applying for the trusted certificate.

  • HOW TO - Create new from clipboard and process multiple files - please help

    Need help - have new version of photoshop on trial only ATM...
    Want to know - HOW TO:
    1. Create new from clipbaord
    2. Process multiple files
    Please help.

    For clipboard copy, I start with File > New and the size will be set to what's in the clipboard. Then once the new file is opened, Edit > Paste will place the clipboard contents as a layer in the new document.
    You must remember to use the command Layer > Flatten Image of you want to save as jpeg or any other file format that doesn't support layers.
    For processing multiple files,
    File > Automate > Batch or
    File > Scripts > Image Processor...
    Check the User guide or google information for those commands if you have specific needs.
    Gene

  • How can create schema from this document.

    Thank you for reply~
    The following is that I have.
    <?xml version='1.0'?>
    <conference>
    <proceedings key="AlbenR00">
    <pro_book>
    <editor>Lauralee Alben</editor>
    <editor>Michael Rigsby</editor>
    <title>Envisioning the E-Quarium: Strategic Design Planning for the Monterey Bay Aquarium''s Website.</title>
    <pages>452-454</pages>
    <year>2000</year>
    <booktitle>Symposium on Designing Interactive Systems</booktitle>
    <series> <--declared with ANY in DTD
    <href>db/conf/eld.htm</href>
    <source>Information Retrieval</source>
    </series>
    </pro_book>
    </proceedings>
    </conference>
    I want to create DB schema from this document, but because I don't know how the document is stored in Oracle8i with object-relational schema when the document has more two level deep.
    (In sample of XSU,all XML documents has only one level deep.)
    Would you create schema from above simple document,please? It will be very helpful to me!!
    Thank you for reading my e-mail.

    Just stop using it and remove any data from your profile that you don't want there. You can't actually remove your account or your old posts from the server.
    If you have registered to have notification emails sent to you, click 'My Stuff' at top right, select 'Preferences' , then in the next page select the 'Email Notification Preferences' tab and click all the 'No' radio buttons. Then click 'Save'.
    If you already have notifications set on some threads you will still get emails from them. Click on your username at the top, then under 'Actions' in the right sidebar, select "'Manage email notifications.' This will show the threads you've set up notifications on in the past. Select those you want to stop and click the 'Remove Selected Notifications' button at bottom.

  • How to Create Hierarchy From Flat file Structure

    Hi Gurus,
    There is a scenario for me regarding the Hierarchy.
    Required Hierarchy structure - Region>Director>Manager-->Sales id
    I have flat file which gives the info like user id , sales id , manager id, director id.
    But the transaction data Flat file has structure with sales id, region id, sales amt, sales qty.
    Note : Region id is another Master Data.
    How i can create hierarchy from the first flat file which doesnot have region info in that but it is available in the transaction data Flat file.
    Is there anyway we can create hierarchy based on the first Flat file structure which contains more that 1,00,000 records.
    Try to Suggest me in this regard .
    This is urgent.
    Regards,
    Mano

    Hi Mano,
                    Defining the source system from which to load data
    Choose the source system tree File  ® Create.
           2.      Defining the InfoSource for which you want to load data
    Optional: choose InfoSource Tree ® Root (InfoSources) ® Create Application Components.
    Choose InfoSource Tree ® Your Application Component ® Other Functions  ® Create InfoSource 3.x ® Direct Update.
    Choose an InfoObject from the proposal list, and specify a name and a description.
           3.      Assigning the source system to the InfoSource
    Choose InfoSource Tree ® Your Application Component ® Your InfoSource ® Assign Source System. The transfer structure maintenance screen appears.
    The system automatically generates DataSources for the three different data types to which you can load data.
    &#9675;       Attributes
    &#9675;       Texts
    &#9675;       Hierarchies (if the InfoObject has access to hierarchies)
    The system automatically generates the transfer structure, the transfer rules, and the communication structure (for attributes and texts).
           4.      Maintaining the transfer structure / transfer rules
    Select the DataSource for uploading hierarchies.
    IDoc transfer method: The system automatically generates a proposal for the DataSource and the transfer structure. This consists of an entry for the InfoObject for which hierarchies are loaded. With this transfer method, the structure is converted to the structure of the PSA during loading, which affects performance.
    PSA transfer method: The transfer methods and the communication structure are also generated here.
           5.      Maintaining the hierarchy
    Choose Hierarchy Maintenance, and specify a technical name and a description of the hierarchy
    Hope this helps
    Regards
    Karthik
    Assign points if Helpful

  • How to create BP from existing vendors optionally?

    Hi,
    how can I create RE business partners from existing vendors for some optional vendors only?
    Does the vendor synchronization (Cross-Application Components - Master Data Synchronization - Customer/Vendor Integration) mean that a BP is created for each vendor in the specific account group?
    I've tried to define the configuration settings but haven't found the solution for this yet. Please advise.
    - BP grouping assigned to number range
    - one FI account group is assigned to BP grouping
    - BP role (BP role category, BP view) defined
    - in Vendor role link, is the assignment of Role category "optional"?
    Thanks!

    Hi,
    thanks for your comment.  I need to check this option too. 
    However, in this case this does not seem like the best option regarding the workload of users. If they have already xxx vendors in FICO, it does not seem like a very efficient way to create those first also as BP, and then link these records.
    It would be much easier to only create the BP based on vendor data with FLBPC1, and save the double work.
    Based on SAP documentation, I've understood that FLBPC1 Create BP from vendor is meant for this purpose, so I would like to use this option.
    Please advise. Has anyone used FLBPC1 Create BP from vendor successfully?
    Thanks!

  • How to create ringtone from my music?

    I've been able to download some of my short music clips and use the clips as ringtones.  However, for the longer pieces of music, I want to use just 30 second of it.  I've already imported the audio file into my BB's micro SD card. 
    The BB Media Manager Help Center provides the following instructions (below), but when I try to right-click on the file, I don't get the "Edit with Quick Sound Editor" function at all.  I've tried everything to get this function with no avail.  Please help!
    You can create ringtones from existing audio clips—such as your favorite song—with the Quick Sound Editor.
    To create a ringtone:
    In Media Manager, browse to the audio file from which you want to create a ring tone.
    Right-click the audio file and choose Edit with Quick Sound Editor.
    If necessary, display the Trim & Fade view by clicking Trim Fade.
    Move the play head to the beginning of the section you want to use as your ringtone, either by clicking Preview or by clicking the waveform.
    Click Set Start.
    Move the play head to the end of the section you want to use as your ringtone.
    Click Set End.
    Click Create Ringtone.
    Specify a file name and location for the new file, and click Save.
    To exit from Quick Sound Editor, click Close.
    The ringtone is added to the All Music > Ringtone Smart View.
    Solved!
    Go to Solution.

    Hi and welcome to the forums,
    Here are some alternatives in the thread:
    http://supportforums.blackberry.com/rim/board/mess​age?board.id=8300&thread.id=10501
    Please let me know if this helps!
    Thanks!
    Click Accept as Solution for posts that have solved your issue(s)!
    Be sure to click Like! for those who have helped you.
    Install BlackBerry Protect it's a free application designed to help find your lost BlackBerry smartphone, and keep the information on it secure.

Maybe you are looking for

  • Solution to Iphone 5 battery drain iOS 6.02

    Like many people I just bought a new Iphone 5 and noticed that the power drains very quickly compared to my previous Iphone 3GS, 4 and 4S. I tried many of the suggestions online such as turning off wireless, brightness, deleting this and that. I even

  • Why is the Creative Cloud desktop app not seeing that Photoshop CC is already installed?

    I have Photoshop CC 32bit and 64bit installed on a W7 64bit, 3770, 32Gb ram etc system.  No operating problems with Photoshop CC at all.  But I have just used the Creative Cloud desktop app (I'm not sure if "app" is the right term - it looks like a C

  • Anyone use User Device Affinity?

    Just wanted to know if anyone is using User Affinity to deploy software and if you are, can you please share any headaches I should be on the lookout for. We use it in limited fashion (via AD Group Membership) and its working well. I would like to ex

  • Button that will pause project AND open URL

    how can I create a button, that upon clicking will pause the movie, and open a URL in another window. I've got javascript that opens another window, but the movie doesn't pause. I uncheck the 'pause movie' box because I want the user to have the opti

  • Wi-fi difficulty

    When I first started using my Ipod Touch I had no difficulties connecting to my local Wi-fi connection. It then asked me to create my Apple ID, but I kept getting a server error, so I put it off for a bit. Since then, I have not been able to reconnec