[vorbis-dev] a listening test tool

Robert Voigt robert.voigt at gmx.de
Thu Oct 5 16:36:08 PDT 2000



When I played with those 3 arrays toneatt, peakatt, noiseatt in
vorbis_info_psy in mode_?.h to tune the psychoacoustics, I didn't like
having to compile after every change and encode again. So I wrote this
hack of oggenc that reads changes to the 3 arrays at runtime, before it
starts encoding. 

This is useful to save the compiling. But I'd like to extend it so that
it constantly encodes a snippet of music and plays it back, reading
changes to the arrays everytime it starts encoding. This way I could
listen to the different encodings without pause. 

Please give comments and suggestions? I would also need help to
integrate the playback functionality in oggenc, or whatever that will be
called.

Here are the details of this hack:

It reads numbers from test.txt. That file contains the initialization
tables of 
toneatt, peakatt, noiseatt from mode_A.h. The original numbers are still
there to see what's in there, but they aren't read. Then, after the ".",
there are the numbers that can be added or subtracted from the original
values( "- 0" at the moment). You can change these numbers by hand or
rows and columns of them with macros in emacs.

To try it out tou must:

copy psyhack.c and psyhack.h to the vorbis-tools dir

add  #include "psyhack.h" to oggenc.c

add: "psyhack(mode->psy_param[0]);" to function choose_mode() in
oggenc.c, right before "return mode;"

add psyhack.o to the Makefile in the oggenc section

change the path in psyhack.c in the fopen() call line 20 to the path
where you 
put test.txt



  1,/* tonemaskp */
 /*|_0___|  |10___|  |20___|  |30___|  |40___|  |50___|  |60___|  |70___|  |80___|  |90___| |100___|       */
 {{-30.- 0, -35.- 0, -35.- 0, -40.- 0, -40.- 0, -50.- 0, -60.- 0, -70.- 0, -80.- 0, -90.- 0,-100.- 0}, /*63*/
  {-30.- 0, -35.- 0, -35.- 0, -40.- 0, -40.- 0, -50.- 0, -60.- 0, -70.- 0, -80.- 0, -90.- 0,-100.- 0}, /*88*/
  {-30.- 0, -35.- 0, -35.- 0, -40.- 0, -40.- 0, -50.- 0, -60.- 0, -70.- 0, -80.- 0, -90.- 0,-100.- 0}, /*125*/
  {-30.- 0, -35.- 0, -35.- 0, -40.- 0, -40.- 0, -50.- 0, -60.- 0, -70.- 0, -80.- 0, -90.- 0,-100.- 0}, /*175*/
  {-30.- 0, -35.- 0, -35.- 0, -40.- 0, -40.- 0, -50.- 0, -60.- 0, -70.- 0, -80.- 0, -90.- 0,-100.- 0}, /*250*/
  {-30.- 0, -35.- 0, -35.- 0, -40.- 0, -40.- 0, -50.- 0, -60.- 0, -70.- 0, -80.- 0, -90.- 0,-100.- 0}, /*350*/
  {-30.- 0, -35.- 0, -35.- 0, -40.- 0, -40.- 0, -50.- 0, -60.- 0, -70.- 0, -80.- 0, -90.- 0,-100.- 0}, /*500*/
  {-30.- 0, -35.- 0, -35.- 0, -40.- 0, -40.- 0, -50.- 0, -60.- 0, -70.- 0, -80.- 0, -90.- 0,-100.- 0}, /*700*/
  {-30.- 0, -35.- 0, -35.- 0, -40.- 0, -40.- 0, -50.- 0, -60.- 0, -70.- 0, -80.- 0, -90.- 0,-100.- 0}, /*100*/
  {-30.- 0, -35.- 0, -35.- 0, -40.- 0, -40.- 0, -50.- 0, -60.- 0, -70.- 0, -80.- 0, -90.- 0,-100.- 0}, /*140*/
  {-40.- 0, -40.- 0, -40.- 0, -40.- 0, -40.- 0, -50.- 0, -60.- 0, -70.- 0, -80.- 0, -90.- 0,-100.- 0}, /*200*/
  {-40.- 0, -40.- 0, -40.- 0, -40.- 0, -40.- 0, -50.- 0, -60.- 0, -70.- 0, -80.- 0, -90.- 0,-100.- 0}, /*280*/
  {-30.- 0, -35.- 0, -35.- 0, -40.- 0, -40.- 0, -50.- 0, -60.- 0, -70.- 0, -80.- 0, -90.- 0,-100.- 0}, /*400*/
  {-30.- 0, -30.- 0, -35.- 0, -37.- 0, -40.- 0, -50.- 0, -60.- 0, -70.- 0, -80.- 0, -90.- 0,-100.- 0}, /*560*/
  {-20.- 0, -25.- 0, -30.- 0, -35.- 0, -35.- 0, -50.- 0, -60.- 0, -70.- 0, -80.- 0, -90.- 0,-100.- 0}, /*800*/
  {-20.- 0, -25.- 0, -30.- 0, -33.- 0, -35.- 0, -45.- 0, -55.- 0, -65.- 0, -75.- 0, -90.- 0,-100.- 0}, /*115*/
  {-20.- 0, -24.- 0, -26.- 0, -32.- 0, -35.- 0, -45.- 0, -55.- 0, -65.- 0, -75.- 0, -90.- 0,-100.- 0}, /*160*/
  },

 1,/* peakattp */
 /*|_0___|  |10___|  |20___|  |30___|  |40___|  |50___|  |60___|  |70___|  |80___|  |90___| |100___|       */
 {{-14.- 0, -16.- 0, -18.- 0, -19.- 0, -20.- 0, -21.- 0, -22.- 0, -22.- 0, -22.- 0, -22.- 0, -22.- 0}, /*63*/
  {-14.- 0, -16.- 0, -18.- 0, -19.- 0, -20.- 0, -21.- 0, -22.- 0, -22.- 0, -22.- 0, -22.- 0, -22.- 0}, /*88*/
  {-14.- 0, -16.- 0, -18.- 0, -19.- 0, -20.- 0, -21.- 0, -22.- 0, -22.- 0, -22.- 0, -22.- 0, -22.- 0}, /*125*/
  { -7.- 0,  -8.- 0,  -9.- 0, -10.- 0, -10.- 0, -11.- 0, -12.- 0, -13.- 0, -15.- 0, -18.- 0, -20.- 0}, /*80*/
  { -7.- 0,  -8.- 0,  -9.- 0, -10.- 0, -10.- 0, -11.- 0, -12.- 0, -13.- 0, -15.- 0, -18.- 0, -20.- 0}, /*80*/
  { -7.- 0,  -8.- 0,  -9.- 0, -10.- 0, -10.- 0, -11.- 0, -12.- 0, -13.- 0, -15.- 0, -18.- 0, -20.- 0}, /*80*/
  { -7.- 0,  -8.- 0,  -9.- 0, -10.- 0, -10.- 0, -11.- 0, -12.- 0, -13.- 0, -15.- 0, -18.- 0, -20.- 0}, /*80*/
  { -7.- 0,  -8.- 0,  -9.- 0, -10.- 0, -10.- 0, -11.- 0, -12.- 0, -13.- 0, -15.- 0, -18.- 0, -20.- 0}, /*80*/
  { -7.- 0,  -8.- 0,  -9.- 0, -10.- 0, -10.- 0, -11.- 0, -12.- 0, -13.- 0, -15.- 0, -18.- 0, -20.- 0}, /*80*/
  { -7.- 0,  -8.- 0,  -9.- 0, -10.- 0, -10.- 0, -11.- 0, -12.- 0, -13.- 0, -15.- 0, -18.- 0, -20.- 0}, /*80*/
  { -7.- 0,  -8.- 0,  -9.- 0, -10.- 0, -10.- 0, -11.- 0, -12.- 0, -13.- 0, -15.- 0, -18.- 0, -20.- 0}, /*80*/
  { -7.- 0,  -8.- 0,  -9.- 0, -10.- 0, -10.- 0, -11.- 0, -12.- 0, -13.- 0, -15.- 0, -18.- 0, -20.- 0}, /*80*/
  { -7.- 0,  -8.- 0,  -9.- 0, -10.- 0, -10.- 0, -11.- 0, -12.- 0, -13.- 0, -15.- 0, -18.- 0, -20.- 0}, /*80*/
  { -7.- 0,  -8.- 0,  -9.- 0, -10.- 0, -10.- 0, -11.- 0, -12.- 0, -13.- 0, -15.- 0, -18.- 0, -20.- 0}, /*80*/
  { -7.- 0,  -8.- 0,  -9.- 0, -10.- 0, -10.- 0, -11.- 0, -12.- 0, -13.- 0, -15.- 0, -16.- 0, -17.- 0}, /*80*/
  { -6.- 0,  -7.- 0,  -9.- 0,  -9.- 0,  -9.- 0,  -9.- 0, -10.- 0, -11.- 0, -12.- 0, -13.- 0, -14.- 0}, /*115*/
  { -6.- 0,  -6.- 0,  -9.- 0,  -9.- 0,  -9.- 0,  -9.- 0,  -9.- 0,  -9.- 0, -10.- 0, -11.- 0, -12.- 0}, /*160*/
 },

 1,/*noisemaskp */
 /*|_0___|  |10___|  |20___|  |30___|  |40___|  |50___|  |60___| |_70___| |_80___| |_90___| |100___|       */
 {{-99.- 0, -99.- 0, -99.- 0, -99.- 0, -99.- 0, -99.- 0, -99.- 0,-199.- 0,-199.- 0,-199.- 0,-199.- 0}, /*63*/
  {-99.- 0, -99.- 0, -99.- 0, -99.- 0, -99.- 0, -99.- 0, -99.- 0,-199.- 0,-199.- 0,-199.- 0,-199.- 0}, /*88*/
  {-99.- 0, -99.- 0, -99.- 0, -99.- 0, -99.- 0, -99.- 0, -99.- 0,-199.- 0,-199.- 0,-199.- 0,-199.- 0}, /*125*/
  {-99.- 0, -99.- 0, -99.- 0, -99.- 0, -99.- 0, -99.- 0, -99.- 0,-199.- 0,-199.- 0,-199.- 0,-199.- 0}, /*175*/
  {-99.- 0, -99.- 0, -99.- 0, -99.- 0, -99.- 0, -99.- 0, -99.- 0,-199.- 0,-199.- 0,-199.- 0,-199.- 0}, /*250*/
  {-99.- 0, -99.- 0, -99.- 0, -99.- 0, -99.- 0, -99.- 0, -99.- 0,-199.- 0,-199.- 0,-199.- 0,-199.- 0}, /*350*/
  {-99.- 0, -99.- 0, -99.- 0, -99.- 0, -99.- 0, -99.- 0, -99.- 0,-199.- 0,-199.- 0,-199.- 0,-199.- 0}, /*500*/
  {  6.- 0,   6.- 0,   6.- 0,   2.- 0,   2.- 0,   2.- 0,   2.- 0,   2.- 0,   2.- 0,   1.- 0,   0.- 0}, /*700*/
  {  6.- 0,   6.- 0,   6.- 0,   5.- 0,   5.- 0,   5.- 0,   5.- 0,   5.- 0,   5.- 0,   4.- 0,   3.- 0}, /*100*/
  {  6.- 0,   6.- 0,   6.- 0,   5.- 0,   5.- 0,   5.- 0,   5.- 0,   5.- 0,   5.- 0,   4.- 0,   3.- 0}, /*140*/
  {  6.- 0,   6.- 0,   6.- 0,   5.- 0,   5.- 0,   5.- 0,   5.- 0,   5.- 0,   5.- 0,   4.- 0,   3.- 0}, /*200*/
  {  6.- 0,   6.- 0,   6.- 0,   5.- 0,   5.- 0,   5.- 0,   5.- 0,   5.- 0,   5.- 0,   4.- 0,   3.- 0}, /*280*/
  {  6.- 0,   6.- 0,   6.- 0,   5.- 0,   5.- 0,   5.- 0,   5.- 0,   5.- 0,   5.- 0,   4.- 0,   3.- 0}, /*400*/
  { 10.- 0,  10.- 0,  10.- 0,  10.- 0,  10.- 0,  10.- 0,   8.- 0,   8.- 0,   6.- 0,   6.- 0,   6.- 0}, /*560*/
  { 10.- 0,  10.- 0,  10.- 0,  10.- 0,  10.- 0,  10.- 0,   8.- 0,   8.- 0,   8.- 0,   8.- 0,   8.- 0}, /*800*/
  { 10.- 0,  10.- 0,  10.- 0,  10.- 0,  10.- 0,  10.- 0,  10.- 0,  10.- 0,  10.- 0,  10.- 0,  10.- 0}, /*115*/
  { 10.- 0,  10.- 0,  10.- 0,  10.- 0,  10.- 0,  10.- 0,  10.- 0,  10.- 0,  10.- 0,  10.- 0,  10.- 0}, /*160*/
 },




#include <stdio.h> 
#include <stdlib.h>
#include "psyhack.h"
#include <vorbis/codec.h>

#define Bufsize 10000

void psyhack(vorbis_info_psy *psy_param)
{
  char buf[Bufsize];
  char sign;
  char valuebuf[2];
  double value;
  int i, j, k, n = 0;
  int kindofatt = 0;
  int numdots = 0; 
  int numbytesread = 0;

  FILE *f = fopen("/home/robert/psyhack/test.txt", "r");
  numbytesread = fread(buf, 1, Bufsize, f);
  fclose(f);

  for(i = 0; i < numbytesread; i++) /* main loop through whole file */
    {
      if( (buf[i] == '{') && (buf[i+1] == '{') )
        {
          kindofatt++;
        }
      if(buf[i] == '.') /* pick the following 3 characters */
        {
          sign = buf[i+1];
          valuebuf[0] = buf[i+2];
          valuebuf[1] = buf[i+3];
          value = atof(valuebuf);
          numdots++;
  
          k = (numdots - 1) % P_LEVELS; 
          n = numdots % (P_BANDS * P_LEVELS);
          j = (int) ( (n - 1) / P_LEVELS);
          
          if(kindofatt == 1) addvalue(&psy_param->toneatt[j][k], value, sign);
          else if(kindofatt == 2) addvalue(&psy_param->peakatt[j][k], value, sign);
          else if(kindofatt == 3) addvalue(&psy_param->noiseatt[j][k], value, sign);
          else printf("We have a problem in psyhack.c \n");
        }
    }

/*  uncomment this if you want the actual values of the arrays being printed (to see what has actually happened to them) */
/*    for(j = 0; j < P_BANDS; j++) */
/*      { */
/*        for(k = 0; k < P_LEVELS; k++) */
/*  	{ */
/*  	  if(k == 0) */
/*  	    printf("\n"); */
/*  	  printf("%f  ", psy_param->toneatt[j][k]); */
/*  	} */
/*      } */
/*    printf("\n"); */
/*   for(j = 0; j < P_BANDS; j++) */
/*      { */
/*        for(k = 0; k < P_LEVELS; k++) */
/*  	{ */
/*  	  if(k == 0) */
/*  	    printf("\n"); */
/*  	  printf("%f  ", psy_param->peakatt[j][k]); */
/*  	} */
/*      } */
/*   printf("\n"); */
/*   for(j = 0; j < P_BANDS; j++) */
/*      { */
/*        for(k = 0; k < P_LEVELS; k++) */
/*  	{ */
/*  	  if(k == 0) */
/*  	    printf("\n"); */
/*  	  printf("%f  ", psy_param->noiseatt[j][k]); */
/*  	} */
/*      } */
}

void addvalue(double *originalvalue, double changevalue, char sign)
{
  if(sign == '+')
    *originalvalue += changevalue;

  if(sign == '-')
    *originalvalue -= changevalue;
}




#ifndef __PSYHACK_H
#define __PSYHACK_H

#include <vorbis/codec.h>

void psyhack(vorbis_info_psy *psy_param);

void addvalue(double *originalvalue, double changevalue, char sign);

#endif

--- >8 ----
List archives:  http://www.xiph.org/archives/
Ogg project homepage: http://www.xiph.org/ogg/
To unsubscribe from this list, send a message to 'vorbis-dev-request at xiph.org'
containing only the word 'unsubscribe' in the body.  No subject is needed.
Unsubscribe messages sent to the list will be ignored/filtered.



More information about the Vorbis-dev mailing list