いらないモノ、ひつようなモノ

書籍、音楽、そして若干のテクノロジー

Loris Analysis Example

It is a simple matter to write a small program that uses the Loris procedural interface to analyze a sound and store the partials, or synthesize a new sound from the partials and create a new samples file.

音ををまず分析しpartialにデータを保存し底から新しい音を合成するサンプルである。

This C program demonstrates the use of the Loris procedural interface to analyze a clarinet tone having a fundamental frequency of approximately 415 Hz. The partials are exported to a Sound Description Interchange Format (SDIF) data file. The clarinet sound is then reconstructed from the partials, and the synthesized samples are exported to a samples file in the AIFF format.

以下のCのコードでLorisの利用方法を示す。
データとして利用するクラリネットの音は基本周波数としておおよそ415Hzを持つ。partialはSDIFファイルに蓄積する。再び音を合成しAIFFファイルに蓄積するようなプログラムになっている。

/*
 *  analysis_example.c
 *
 *  Use the Loris procedural interface to perform a
 *  Reassigned Bandwidth-Enhanced analysis of a 
 *  clarinet tone, having fundamental frequency of
 *  approximately 415 Hz.
 */
#include <stdio.h>
#include <string.h>
#include <loris.h>

int main( void )
{
    const double FUNDAMENTAL = 415.0; 
                   /* G#4 */
    const unsigned long BUFSZ = 44100 * 4; 
                   /* approx. 4 seconds */

    PartialList * partials = NULL;
    double samples[ BUFSZ ];
    double sr;
    unsigned int nsamps;
    
    /* import the clarinet samples */
    nsamps = importAiff("clarinet.aiff", samples, BUFSZ, &sr);
    
    /* configure the Loris analyzer, use frequency
       resolution equal to 80% of the fundamental
       frequency, main lobe width equal to the 
       fundamental frequency, and frequency drift 
       equal to 20% of the fundamental frequency
    */
    analyzer_configure( .8 * FUNDAMENTAL, FUNDAMENTAL );
    analyzer_setFreqDrift( .2 * FUNDAMENTAL );  
                   /* approx. 83 Hz */
    
    /* analyze and store partials */
    partials = createPartialList();
    analyze( samples, nsamps, sr, partials );
  
    /* export to SDIF file */
    exportSdif("clarinet.sdif", partials );
    
    /* synthesize */
    memset( samples, 0, BUFSZ * sizeof(double) );
    nsamps = synthesize( partials, samples, BUFSZ, sr );
    
    /* export samples to AIFF file */
    exportAiff( "synth.aiff", samples, nsamps, sr, 16 );
    
    /* cleanup */
    destroyPartialList( partials );
    
    return 0;
} 

In this analysis, the analyzer is configured to have frequency resolution equal to 80% of the fundamental frequency (a good rule of thumb), and analysis window width equal to the fundamental frequency. The only other analyzer parameter that is configured is the frequenecy drift, which is set at 20% of the fundamental frequency to prevent partials having large and rapid variations in their frequency envelopes. The other parameters of the analzer are configured automatically from the frequency resolution and window width.

この分析では周波数解像度は基本周波数の80%に設定され、分析窓の幅は基本周波数と同じに設定されている。デフォルト値から変更するパラメータは周波数ドリフトパラメータである。これは基本周波数の20%に設定され、周波数エンベロップで急速で大きな変化のあるpartialを取り除くために設定されている。他のパラメータはデフォルト値で周波数解像度と解析窓の幅から決められる。

By the way, in a Unix-like environment, the same analysis can be performed using the loris_analyze command line utility.

以下のコマンドによっても同じことが実現できる。

% loris_analyze 332 415 clarinet.aiff -drift 83 -o clarinet.sdif -render synth.aiff