• Posts
  • RSS
  • ◂◂RSS
  • Contact

  • Wrapping Bass: Implementation

    February 3rd, 2012
    octaveless, music  [html]
    After thinking yesterday about octaveless notes I decided to write something to generate the tones I had in mind. Here they are as two-second mp3s:
    Bb B C Db
    A D
    Ab Eb
    G Gb F E
    The code is on github. It uses portaudio so it should work cross platform if you want to compile it. The important parts of the code are:
    #define sine(i,F) ((float) sin( (((double)(i)*(double)(F))/SAMPLE_RATE) * M_PI * 2. ))
    
    float freq(float note)
    {
      return 440*(pow(2, (note-69.0)/12));
    }
    
    float intensity(float note, int octave)
    {
      float bass_n = fmod(note, 12);
    
      switch(octave) {
      case 0:
        return 0.00 + 0.01*bass_n;
      case 1:
        return 0.12 + 0.01*bass_n;
      case 2:
        return 0.24 + 0.01*bass_n;
      case 3:
        return 0.32 - 0.01*bass_n;
      case 4:
        return 0.22 - 0.01*bass_n;
      case 5:
        return 0.10 - 0.01*bass_n;
      }
      return 0; // never reached
    }
    
    float synth(float phase, float note) {
      return pow(2,(sine(phase, note)));
    }
    
    # A440 = 69, as in midi
    # phase is constantly increasing, once per sample
    #
    float sample_val(float note, unsigned int phase)
    {
      note = fmod(note, 12);
    
      return log2(synth(phase, freq(note + 12*0)) * intensity(note, 0) +
                  synth(phase, freq(note + 12*1)) * intensity(note, 1) +
                  synth(phase, freq(note + 12*2)) * intensity(note, 2) +
                  synth(phase, freq(note + 12*3)) * intensity(note, 3) +
                  synth(phase, freq(note + 12*4)) * intensity(note, 4) +
                  synth(phase, freq(note + 12*5)) * intensity(note, 5));
    }
    
    # call sample_val as:
    # for (int i = 0 ; i < 1000000 ; i++)
    #   send_to_speaker(sample_val(69, i));
    

    Comment via: google plus, facebook, r/WeAreTheMusicMakers

    Recent posts on blogs I like:

    The Limit of Circles in the Suburbs

    In dense urban cores, it’s valuable to run circular rail lines. They connect dense near-center neighborhoods to one another without going through the more congested center, and help make transferring between parallel lines more efficient, again through av…

    via Pedestrian Observations September 6, 2020

    Collections: Bread, How Did They Make It? Addendum: Rice!

    As an addendum on to our four-part look at the general structures of the farming of cereal grains (I, II, III, IV) this post is going to briefly discuss some of the key ways that the structures of rice farming differ from the structures of wheat and barle…

    via A Collection of Unmitigated Pedantry September 4, 2020

    Notes on “Anthropology of Childhood” by David Lancy

    I read David Lancy’s “The Anthropology of Childhood: Cherubs, Chattel, and Changelings” and highlighted some passages. A lot of passages, it turns out. [content note: discussion of abortion and infanticide, including infanticide of children with disabilit…

    via The whole sky August 27, 2020

    more     (via openring)


  • Posts
  • RSS
  • ◂◂RSS
  • Contact