[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

reading wav files into array

Posted on 2006-04-20
13
Medium Priority
?
861 Views
Last Modified: 2008-02-01
hello all;

please help me about his subject.I want to read a wav file into a double array.No time to learn.just quick help.
thanks.
0
Comment
Question by:dervisakyuz
  • 3
  • 2
  • 2
  • +3
10 Comments
 
LVL 86

Expert Comment

by:CEHJ
ID: 16502218
Which parts of it?
0
 
LVL 14

Expert Comment

by:StillUnAware
ID: 16502223
You can read the file to bytes array, not to double array. You'll have to apply some kind of conversion or at least a type cast later.
0
 
LVL 14

Accepted Solution

by:
StillUnAware earned 256 total points
ID: 16502271
Actually You can read a double, but it will be interpreted by Java the way You won't be satisfied with. For that You use DataInputStream:

DataInputStream dis = new DataInputStream(new FileInputStream("f.wav"));
double d = dis.readDouble();

I guess the class RandomAccessFile will the best fit Your needs, check it here:
http://java.sun.com/j2se/1.5.0/docs/api/java/io/RandomAccessFile.html

Also notice that all the classes mentioned here are from package java.io , which should be imported when used.
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 86

Assisted Solution

by:CEHJ
CEHJ earned 248 total points
ID: 16502297
0
 
LVL 92

Assisted Solution

by:objects
objects earned 248 total points
ID: 16503194
0
 
LVL 23

Assisted Solution

by:Siva Prasanna Kumar
Siva Prasanna Kumar earned 248 total points
ID: 16504050
0
 
LVL 30

Expert Comment

by:Mayank S
ID: 16505039
BTW, this is a duplicate of the already posted question:

http://www.experts-exchange.com/Programming/Programming_Languages/Java/Q_21821007.html
0
 

Author Comment

by:dervisakyuz
ID: 16505316
this are good but i am very new about java.

this is a code in c++ what i want..but i need it in java??

any excelllent expert can do it??

#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>

#include "aec.h"

#define TAPS        (80*8)

typedef signed short MONO;

typedef struct {
  signed short l;
  signed short r;
} STEREO;

float dB2q(float dB)
{
  /* Dezibel to Ratio */
  return powf(10.0f, dB / 20.0f);
}

float q2dB(float q)
{
  /* Ratio to Dezibel */
  return 20.0f * log10f(q);
}

/* Read a raw audio file (8KHz sample frequency, 16bit PCM, stereo)
 * from stdin, echo cancel it and write it to stdout
 */
int main(int argc, char *argv[])
{
  STEREO inbuf[TAPS], outbuf[TAPS];

  fprintf(stderr, "usage: aec_test [ambient in dB] <in.raw >out.raw\n");

  AEC aec;

  if (argc >= 2) {
    aec.setambient(MAXPCM*dB2q(atof(argv[1])));    
  }

  int taps;
  while (taps = fread(inbuf, sizeof(STEREO), TAPS, stdin)) {
    int i;
    for (i = 0; i < taps; ++i) {
      int s0 = inbuf[i].l;      /* left channel microphone */
      int s1 = inbuf[i].r;      /* right channel speaker */

      /* and do NLMS */
      s0 = aec.doAEC(s0, s1);

      /* copy back */
      outbuf[i].l = 0;          /* left channel silence */
      outbuf[i].r = s0;         /* right channel echo cancelled mic */
    }

    fwrite(outbuf, sizeof(STEREO), taps, stdout);
  }

  float ambient = aec.getambient();
  float ambientdB = q2dB(ambient / 32767.0f);
  fprintf(stderr, "Ambient = %2.0f dB\n", ambientdB);
  fflush(NULL);
  return 0;
}
0
 
LVL 30

Expert Comment

by:Mayank S
ID: 16505337
Pls don't post on this duplicate question anymore. Let's continue the discussion on the original one (the link I posted).
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 16685851
:-)
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
In this post we will learn how to make Android Gesture Tutorial and give different functionality whenever a user Touch or Scroll android screen.
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
This video teaches viewers about errors in exception handling.
Suggested Courses
Course of the Month19 days, 11 hours left to enroll

873 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question