Annonce

>>> Bienvenue sur codelab! >>> Première visite ? >>> quelques mots sur codelab //// une carte des membres//// (apéros) codelab


#1 2010-11-27 14:03:53 sound 8 bit processing ?

aymeric
nouveau membre
Date d'inscription: 2008-11-24
Messages: 7

sound 8 bit processing ?



bonjour a tous

voila

je travaille sur un petit projet processing
ou je voudrais  convertir un fichier texte composé de valeur binaire en son

extrait du fichier texte"
01000100
01100101
01110000
01110101
01101001
01110011
00100000
01101100
01100101
00100000
01100100
11101001
01100010
01110101
01110100
00100000
01100100
01100101
00100000
01101100
00100111"



es que il existe  des fonctions particulier pour ca ?ou une librairie précise?
mon programme charge le fichier texte et lit chaque ligne une par une,
et les traduit en son chaque ligne = c la ou je bloque
merci de votre aide

voila pour l instant a quoi ressemble mon programme

String ligne;
String[] lines;
import arb.soundcipher.*;
int x=50,y=50;

//Minim minim;
//AudioRecorder recorder;


void setup() {

  size(200, 200);
  frameRate(60);

  //background(129,129,129);
  lines = loadStrings("binary.txt");
  println("nombre de lignes : " + lines.length); // length et pas length()
//minim = new Minim(this);
//  ping = minim.loadSnippet("ping.wav");
//   
//   pong = minim.loadSnippet("pong.wav");
//  in = minim.getLineIn(Minim.STEREO, 2048);
//  // create a recorder that  will record from the input to the filename specified, using buffered recording
//  // buffered recording means that all captured audio will be written into a sample buffer
//  // then when save() is called, the contents of the buffer will actually be written to a file
//  // the file will be located in the sketch's root folder.
//  recorder = minim.createRecorder(in, "binary.wav", true);
//    textFont(createFont("SanSerif", 12));

}
void draw() {
    background(129,129,129);
  for(int i = 0; i<lines.length;i++) {// on parcours chaque ligne
    //println(lines[i]);
    // et pour chaque ligne, chaque caractere
    for(int v=0;v<lines[i].length();v++){ // ici il faut des parentheses à length()
      char lecaractere=lines[i].charAt(v);
     
      // fait ce que tu veux avec lecaractere
  // println(lecaractere);
   println(lecaractere);
    delay(300);
    transcode_lettre(x,y,lecaractere);
     }
      }
    }

void transcode_lettre(int x,int y,char lecaractere) {
 
   if(lecaractere=='1') {
        SoundCipher sc1 = new SoundCipher(this);
    sc1.playNote(20, 100, 0.1);//(picth,dynamics,duration)
       
  }
  delay(300);
     if(lecaractere=='0') {
          SoundCipher sc2 = new SoundCipher(this);
     sc2.playNote(60, 100, 0.1);//(picth,dynamics,duration)
     
  }
   }
// if ( recorder.isRecording() )
//  {
//    text("Currently recording...", 5, 15);
//  }
//  else
//  {
//    text("Not recording.", 5, 15);
//  }
//}
//
//
//
//
//void keyReleased()
//{
//  if ( key == 'r' )
//  {
//    // to indicate that you want to start or stop capturing audio data, you must call
//    // beginRecord() and endRecord() on the AudioRecorder object. You can start and stop
//    // as many times as you like, the audio data will be appended to the end of the buffer
//    // (in the case of buffered recording) or to the end of the file (in the case of streamed recording).
//    if ( recorder.isRecording() )
//    {
//      recorder.endRecord();
//    }
//    else
//    {
//      recorder.beginRecord();
//    }
//  }
//  if ( key == 's' )
//  {
//    // we've filled the file out buffer,
//    // now write it to the file we specified in createRecorder
//    // in the case of buffered recording, if the buffer is large,
//    // this will appear to freeze the sketch for sometime
//    // in the case of streamed recording,
//    // it will not freeze as the data is already in the file and all that is being done
//    // is closing the file.
//    // the method returns the recorded audio as an AudioRecording,
//    // see the example  AudioRecorder >> RecordAndPlayback for more about that
//    recorder.save();
//    println("Done saving.");
//  }
//}
//
//void stop()
//{
//  // always close Minim audio classes when you are done with them
//  ping.close();
//
//   pong.close();
//  in.close();
//  minim.stop();
//  super.stop();
//}

Hors ligne

 

#2 2010-11-27 14:05:24 Re : sound 8 bit processing ?

aymeric
nouveau membre
Date d'inscription: 2008-11-24
Messages: 7

Re: sound 8 bit processing ?



a oui , j ai oublié j aimerais traduire le texte en  son 8 bit .
merci

Hors ligne

 

#3 2010-11-29 11:30:42 Re : sound 8 bit processing ?

oyster_twiter
membre
Lieu: saint-herblain
Date d'inscription: 2008-04-01
Messages: 444
Site web

Re: sound 8 bit processing ?



Salut  Aymeric,

Tel que tu présentes ton projet, j'ai l'impression que tu travailles plus pour l'instant à la réalisation d'une sorte de séquenceur audio, ou les notes seraient déclenchées en fonction des valeurs de ton fichier texte :
1 = note de 20 Hz
0 = note de 60 Hz...

Si tu veux faire en sorte que ton fichier txt encode directement du son il te faudra passer par du traitement de ce type (par contre c'est avec la librairie sonia) :
exemple dans lequel j'encode du son sous forme de valeur float, puis en string dans un fichier txt. Et à l'inverse récupération de valeur dans un fichier txt, convertie en string puis en float et finalement écritent dans un sample pour transcoder le texte en son...
de cette façon là tu pourrais générer des valeurs aléatoires dans ton fichier txt par exemple et les transcoder en son...
je sais pas si ça t'aide ...

import pitaru.sonia_v2_9.*; 


Sample kick;
Sample neo;
float[] data; 


void setup()
{
  size(512, 200, P2D);
  Sonia.start(this); 
  kick =  new Sample("beat.wav");
  neo = new Sample(kick.getNumFrames());
}

void draw()
{
  background(0);
}

void keyPressed()
{
  if ( key == 'k' ) {
    kick.play();
    data = new float[kick.getNumFrames()]; //creates a new array the length of the sample 
    kick.read(data);
    String []dataS = str(data);
    saveStrings("export.txt", dataS);
  }
  if (key == 'l') {
    String lines[] = loadStrings("export.txt");
    float [] neoData = new float[lines.length];
    for(int i=0; i<lines.length; i++) {
      neoData[i]=float(lines[i]);
    }
    neo.write(neoData);
    neo.repeat();
  }
}

void stop()
{
  Sonia.stop();
  super.stop();
}

+++

Hors ligne

 

#4 2010-11-29 14:11:45 Re : sound 8 bit processing ?

aymeric
nouveau membre
Date d'inscription: 2008-11-24
Messages: 7

Re: sound 8 bit processing ?



ok en fait j ai un peu changer
je veux qu il charge un txt, composé de valeur binaire

et que le programme lise chaque ligne composé de 8 caractere
et en fonction du caractère lise le son approprié

si premier caractère égale 1 alors --->sound 1 sinon silence
si deuxième caractère égale 2 alors ----> sound 2 sinon silence
etc

le but étant de convertir ce fichier binaire en une piste sonore

ci joint le lien pour le dossier complé en zip
http://aymeric.larvido.syntone.org/dvd3 … nd.pde.zip
String ligne;
String[] lines;
import ddf.minim.*;

Minim minim;
AudioSample bip1;
AudioSample bip2;
AudioSample bip3;
AudioSample bip4;
AudioSample bip5;
AudioSample bip6;
AudioSample bip7;
AudioSample bip8;
int x=50,y=50;

//Minim minim;
//AudioRecorder recorder;


void setup() {

  size(200, 200);
  frameRate(60);

  //background(129,129,129);
  lines = loadStrings("binary.txt");
  println("nombre de lignes : " + lines.length); // length et pas length()
minim = new Minim(this);
  bip1 = minim.loadSample("1.wav",148);
   bip2 = minim.loadSample("2.wav", 2048);
    bip3 = minim.loadSample("3.wav", 2048);
    bip4 = minim.loadSample("4.wav", 2048); 
     bip5 = minim.loadSample("5.wav", 2048);
      bip6 = minim.loadSample("6.wav", 2048);
       bip7 = minim.loadSample("7.wav", 2048);
        bip8 = minim.loadSample("8.wav", 2048);
//  recorder = minim.createRecorder(in, "binary.wav", true);
//    textFont(createFont("SanSerif", 12));

}
void draw() {
    background(129,129,129);
  for(int i = 0; i<lines.length;i++) {// on parcours chaque ligne
    //println(lines[i]);
    // et pour chaque ligne, chaque caractere
    for(int v=0;v<lines[i].length();v++){ // ici il faut des parentheses à length()
      char lecaractere=lines[i].charAt(v);
     
      // fait ce que tu veux avec lecaractere
  // println(lecaractere);
   println(lecaractere);
    delay(300);
    transcode_lettre(x,y,lecaractere);
     }
      }
    }

void transcode_lettre(int x,int y,char lecaractere) {
  String octet=binary(lecaractere,8);
  if(octet.charAt(0)=='1') {
    bip1.trigger();
  }
  if(octet.charAt(1)=='1') {
   bip2.trigger();
  }
  if(octet.charAt(2)=='1') {
     bip3.trigger();
  }
  if(octet.charAt(3)=='1') {
    bip4.trigger();
  } // verical droit

  if(octet.charAt(4)=='1') {
    bip5.trigger();
  }
  if(octet.charAt(5)=='1') {
    bip6.trigger(); // croix h d
  }
  if(octet.charAt(6)=='1') {
    bip7.trigger();
  }
  if(octet.charAt(7)=='1') {
   bip8.trigger();
  }
  }
    void stop()
{
  // always close Minim audio classes when you are done with them
  bip1.close();
  bip2.close();
  bip3.close();
  bip4.close();
  bip5.close();
  bip6.close();
  bip7.close();
  bip8.close();
  minim.stop();
 
  super.stop();
}   

  //delay(300);

Hors ligne

 

fil rss de cette discussion : rss

Pied de page des forums

Powered by FluxBB

codelab, graphisme & code : emoc / 2008-2024