reading wav files into array

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.
dervisakyuzAsked:
Who is Participating?
 
StillUnAwareCommented:
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
 
CEHJCommented:
Which parts of it?
0
 
StillUnAwareCommented:
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
Cloud Class® Course: CompTIA Cloud+

The CompTIA Cloud+ Basic training course will teach you about cloud concepts and models, data storage, networking, and network infrastructure.

 
objectsCommented:
0
 
Mayank SAssociate Director - Product EngineeringCommented:
BTW, this is a duplicate of the already posted question:

http://www.experts-exchange.com/Programming/Programming_Languages/Java/Q_21821007.html
0
 
dervisakyuzAuthor Commented:
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
 
Mayank SAssociate Director - Product EngineeringCommented:
Pls don't post on this duplicate question anymore. Let's continue the discussion on the original one (the link I posted).
0
 
CEHJCommented:
:-)
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.