SlideShare une entreprise Scribd logo
1  sur  41
Télécharger pour lire hors ligne
真・聴力検査 HACKS

      社外版
    2012/10/24
     @nipotan
以前社内で

• 「聴力検査 HACKS」というネタで LT
• Mac で簡単に聴力検査をしたい
• だけど音を鳴らすのって複雑だよね
say -v Ralph "poe"

#!/bin/sh

v=1
while [ $v -le 200 ]
do
     vol=`echo "scale=2; ${v} / 100" | bc | sed -e 's/^./0./g'`
     echo $vol
     /usr/bin/osascript -e "set Volume ${vol}"
     /usr/bin/say -r 250 -v Ralph "poe"
     v=`expr $v + 1`
done
まぁ…

• 急に作ったネタとは言え、だいぶお粗末
• 音程によって声の人物、発音する単語を変え
    るのはいかがなものか

•   声 ではなく 音 を扱うのに say は不適切
    なのでは?
聴力検査
• オージオメーター
 • 英語で書くと audiometer
 • 健康診断でお馴染み
 • 「 ピーピーピー ポーポーポー
                 と音が
  鳴ってる間はボタンを押してください」

 • もっとオージオメーターを手軽に
ポー そして ピー
• say で poe とか pee とか変じゃない?
• 音程によって低音は Ralph さんとか、高音な
 ら Ya-Ling さんとか、指名するのはなんか変

• そもそも機械的な音声のピーもポーも音程が
 違うだけで同じ音色

 • 何故 Ralph は   poe と言わされたか?
擬音語、奥深い
• カタカナで表現する擬音語
 • 子音は attack (立ち上がり) による
 • 母音は音程による (高 イ→エ→ア→オ→ウ
  低)

 • decay (減衰) は「ン」で表現
• Wikipedia の「子音」の項見るとすごい
        ※個人の感想であり、効果・効能を示すものではありません
擬音語、奥深い
• サイレン「ピーポーピーポー」時報「ピ、ピ、
 ピ、ポーン」鐘「キンコンカンコン」

 • だいたいこの法則に則ってる
 • 「ノーシンピュア」の CM でアッキーナが
  最後に言う「ポンピーン」は唯一例外

• 字が違うが、音程違いだけど同じ音なはず
       ※個人の感想であり、効果・効能を示すものではありません
人間の口腔は複雑

• 声帯から出る音声は同じでも、口腔の形状で
 響き (母音) がかわる

 • イコライザ、トーンカーブ的な役割
• 人間の音声以外は口腔を介していない

       ※個人の感想であり、効果・効能を示すものではありません
人間の口腔は複雑
• ボコーダー、トーキングモジュレータ、ワウ
 ペダル、ワウワウミュート等は人間の口腔に
 よる音色変化をシミュレート
 •   ボコーダー: YMO「Technopolis」


 •   トーキングモジュレータ: BON JOVI「Livin On a Prayer」、同じ BON JOVI で、 な
     かやまきんに君がパスタに粉チーズかける時の BGM「It s My Life」


 •   ワウペダル: Jimi Hendrix「Voodoo Child」、B z 松本孝弘の音作り (マニアック)


 •   ワウワウミュート: Pee Wee Hunt「Somebody Stole My Gal」(吉本新喜劇のテーマ)




                 ※個人の感想であり、効果・効能を示すものではありません
Mac で音を鳴らす
• say はやめて、純粋な音を鳴らす
• Perl で .wav (WAVE) ファイルを作ろう
• データ形式について軽く調べれば出来る
 • ちなみに音に関しては完全にド素人。この
   ネタのために、調べたり頭で考えながら
   作った資料なのであんまり細かいこと言わ
   ないでください

        ※個人の感想であり、効果・効能を示すものではありません
CD 音質
• 44100 Hz, 16bit, ステレオ
 • 秒間 44100 サンプル
 • 1 サンプル 16bit → 2 bytes
 • ステレオはサンプルが左右交互に 2 つ
 • block size は 2 bytes x 2 = 4 bytes
• 44100 (sample) x 4 (bytes) =176,400
  bytes/sec (   172.27KB   1.35Mbps)
WAVE データ形式

• RIFF (Resource Interchange File Format)
  という汎用メタファイル形式

 • RIFF ヘッダと RIFF データからなる
  • WAVE データは RIFF データ内の
      WAVE ヘッダとサブチャンクから構成
WAVE データ形式

• 格納データはリトルエンディアン形式
• Apple が採用する AIFF (Audio Interchange
  File Format) は似たフォーマットで格納デー
  タはビッグエンディアン形式

 • そもそも RIFF は AIFF を元に作られた?
WAVE データ
      内容         バイト数

    RIFF ヘッダ      8

 WAVE ヘッダ WAVE    4

   fmt チャンク      24∼

   data チャンク      -

あくまで、音を鳴らすための最低限
RIFF ヘッダ

      内容         バイト数


 RIFF 識別子 RIFF    4


これより後ろのデータサイズ
                  4
   (合計サイズ -8)
WAVE ヘッダ

     内容         バイト数




WAVE 識別子 WAVE    4
fmt チャンク
             内容                バイト数
      fmt 識別子 fmt               4
         fmt チャンクの
      これより後ろのデータサイズ
                                4
フォーマット ID (リニア PCM = 1)         2
          チャンネル数
        (モノ:1 ステレオ: 2)
                                2
   サンプリングレート (Hz)               4
          データ速度
    (サンプリングレート x block size)
                                4
          block size            2
             bit 数              2
data チャンク
       内容         バイト数

  data 識別子 data    4

   data チャンクの
                   4
これより後ろのデータサイズ

    音声データ          -
音声データ
    内容        バイト数


左チャンネルのサンプル    2


右チャンネルのサンプル    2


   ↑これが 1 ブロック
1 秒あたり 44100 ブロック
音の基礎
• 440Hz (秒間 440 回振幅) の音はラ (A4)
 • 半分の 220Hz、倍の 880Hz もラ
   (A3, A5)

 • A3∼A5 は用紙サイズではなく A がラを、
   後ろの数字がオクターブを表す

• MIDI データだとオクターブが 1 つ下の扱い
音の基礎
• オクターブ間の周波数を 12 分割したのが音
 階 ((十二)平均律) で、世の中の音楽のデファ
 クト

 • 和声で平均律の不自然さに異を唱える思想
  もあり。「音律」で Wikipedia

• 振幅の幅が音量
• 振幅の形が音色
振幅の形 (波形)
• 代表: 正弦波 (sine)、矩形波 (square)、三角
 波 (triangle)、のこぎり波 (sawtooth)
楽器の音色の違い

• 波形の違い
• attack, decay の違い
• 基音 (fundamental tone) と倍音
  (harmonics) の音量と組み合わせの違い

• トーンの違い

          ※個人の感想であり、効果・効能を示すものではありません
純音

• 楽音と違い、オージオメーターは「純音」
 • 倍音を一切含まない正弦波
 • 自然界には存在しない音 (口笛、音叉、クリ
  スタルガラス楽器演奏が近い)



      ※個人の感想であり、効果・効能を示すものではありません
純音
• アナログでは、ウィーンブリッジ発振回路
 (Wien bridge oscillator) で実現可能

• デジタルでは量子化による誤差が生じる
 • 「完全な正弦波は作れない」
 • サンプリングレート、量子化ビット数を上
  げることで近似的な音は作れる


          ※個人の感想であり、効果・効能を示すものではありません
オージオメータ仕様
• 125Hz, 250Hz, 500Hz, 1000Hz, 2000Hz,
  4000Hz, 8000Hz を出力する

 • シの音 (123.47Hz, 246.94Hz,
   493.88Hz, 987.76Hz ...) に近い

• 音が鳴ってる箇所、無音の箇所の繰り返し
• 左右で鳴り分け (ステレオ)
WAVE で作る純音


• 音声データ生成における Hello World (多分)
• 正弦波を 16bit で表現する


        ※個人の感想であり、効果・効能を示すものではありません
WAVE で作る純音
sub make_sine {
    my($hz, $sec, $lvol, $rvol) = @_;
    my $maxno = 2 ** 16 / 2 - 1; # 32767
    $lvol = $lvol / 100 * $maxno;
    $rvol = $rvol / 100 * $maxno;
    my $length = 44100 * $sec;
    my $sound = '';
    for my $pos (1 .. $length) {
        my $val = sin 2 * 3.14 * $hz * ($pos / 44100);
        $sound .= pack 'v', $val * $lvol; # left
        $sound .= pack 'v', $val * $rvol; # right
    }
    return $sound;
}
WAVE で作る無音

sub make_silent {
    my $sec = shift;
    my $length = 44100 * $sec;
    my $sound = '';
    for my $pos (1 .. $length) {
        $sound .= "0" x 4;
    }
    return $sound;
}
純音無音の繰り返し

sub audiometer {
    my($lr, $oct) = @_;
    my $hz = 500 * 2 ** ($oct - 3);
    my $data = '';
    for my $vol (1 .. 20) {
        my @vol_args = uc($lr) eq 'L' ? ($vol, 0) : (0, $vol);
        $data .= make_sine($hz, 0.3, @vol_args);
        $data .= make_silent(0.2);
    }
    return $data;
}
忘れないで、ヘッダ
my $header = riff_header(length $data);

sub riff_header {
    my $size = shift;
    my $header = 'RIFF';               #   RIFF header
    $header .= pack 'V',   $size + 36; #   following data size
    $header .= 'WAVE';                 #   WAVE header
    $header .= 'fmt ';                 #   fmt header
    $header .= pack 'V',   16;         #   format chunk size
    $header .= pack 'v',   1;          #   format id (PCM = 1)
    $header .= pack 'v',   2;          #   monaural = 1, stereo = 2
    $header .= pack 'V',   44100;      #   sampling rate (44.1kHz)
    $header .= pack 'V',   44100 * 4; #    byte/sec
    $header .= pack 'v',   4;          #   block size (16bit stereo)
    $header .= pack 'v',   16;         #   bit/sample
    $header .= 'data';                 #   data header
    $header .= pack 'V',   $size;      #   data chunk size
    return $header;
}
お洒落に PSGI で
my $app = sub {
    my $env = shift;
    my @path = $env->{REQUEST_URI} =~ m{^/([lr])/([1-7])/?$}i;
    die "invalid path $env->{REQUEST_URI}" unless @path == 2;
    my $wave = audiometer(@path);
    return [
        200,
        [
            'Content-Type'   => 'audio/x-wav',
            'Content-Length' => length($wave) + 44,
        ],
        [
            riff_header(length $wave),
            $wave,
        ],
    ];
};
DEMO
応用: モスキート音
 sub mosquito { return make_sine(17000, 10, 100, 100) }




• 17kHz 以上の音はモスキート音
 • 若者には聞こえるらしいぜ
 • はぁ、どうせ聞こえねーし


                   ※個人の感想であり、効果・効能を示すものではありません
応用: 簡易シーケンサ
sub tone_to_hz {
    my $tone = shift;
    my($scale, $shift, $octave) = $tone =~ /
        ^
        ([A-G])    # A-G
        ([-+b#]?) # -, +, b, #
        ([1-9]?)   # 1-9
        $
    /x;
    return 0 unless $scale;
    my %tone_index = (
        C => -9, D => -7, E => -5, F => -4, G => -2, A => 0, B => 2,
    );
    my $index = $tone_index{$scale};
    if ($shift) {
        my $num = $shift eq '+' || $shift eq '#' ? 1 : -1;
        $index += $num;
    }
    if ($octave && $octave != 3) {
        $index += ($octave - 3) * 12;
    }
    return 440 * (2 ** ($index / 12));
}
応用: 簡易シーケンサ
 sub sequence {
     my $bpm = shift;
     my $crotchet = 60 / $bpm;
     my $seconds = +{
         16 => $crotchet / 4,
         8 => $crotchet / 2,
         4 => $crotchet,
         2 => $crotchet * 2,
         1 => $crotchet * 4,
     };
     my $wave = '';
     for my $data (@_) {
         my($tone, $len, $vol) = @$data;
         $vol ||= 80;
         my $sec = 0;
         for my $note (split /-/, $len) {
             my $dotted = $tone =~ s/.$// ? 1 : 0;
             $sec += $seconds->{$note} * ($dotted ? 1.5 : 1);
         }
         if ($tone eq '-') {
             $wave .= make_silent($sec);
             next;
         }
         $wave .= make_sine(tone_to_hz($tone), $sec, $vol, $vol);
     }
     return $wave;
 }
応用: 簡易シーケンサ
sub heavy_rotation {                       ['C#4', 4],     # ン
    my $bpm = shift;
                                           ['C#4', 4],     # ガ
    my $crotchet = 60 /   $bpm;
    return sequence(                       ['A3',    4],   # ン
        $bpm,                              ['F#3', 4],     # な
        ['E3', 4],        # I
        ['F#3', 4],       # want           ['F#3', 4],     # っ
        ['G#3', '1-4'],   # you            ['G#3', 4],     # て
        ['-',   4],
                                           ['A3',    4],   # る
        ['E3', 4],        # I
        ['F#3', 4],       # need           ['B3',    4],   #   mu
        ['G#3', '1-4'],   # you            ['B3',    4],   #   -
        ['-',   4],                        ['B3',    4],   #   si
        ['E3', 4],        # I              ['G#3',   4],   #   -
        ['F#3', 4],       # love           ['E3',    2],   #   c
        ['G#3', '1-4'],   # you            ['-',     4],
        ['-',   4],                        ['G#3',   4],   #   hea
        ['G#3', 4],       # あ              ['A3',    2],   #   vy
                                           ['C#3',   2],   #   -
        ['A3',   4],      # た
                                           ['E3',    4],   #   ro
        ['B3',   2],      # ま              ['D#3',   4],   #   -
        ['G#3', 2],       # の              ['C#3',   4],   #   ta
                                           ['D#3',   4],   #   -
        ['F#3', 2],       # な              ['E3',    2],   #   tion
        ['E3',   2],      # か          );
                                   }
        ['C#4', 4],       # ガ
この聴力検査方法
• 厳密な聴力の検査には向かない
 • 再生デバイス側でボリュームコントロール
  可能

 • 音波への変換装置の個体差
• あくまで簡易的な検査にとどめましょう
 • 耳の異常を感じたら、早めに耳鼻科へ
まとめ


• あくまで、音を扱ってみただけです
 • でも音を扱うのは基本がわかればちょっと
  楽しくなってくる
おわり


• 質問はあんまり受けたくありません

Contenu connexe

Dernier

論文紹介:Content-Aware Token Sharing for Efficient Semantic Segmentation With Vis...
論文紹介:Content-Aware Token Sharing for Efficient Semantic Segmentation With Vis...論文紹介:Content-Aware Token Sharing for Efficient Semantic Segmentation With Vis...
論文紹介:Content-Aware Token Sharing for Efficient Semantic Segmentation With Vis...Toru Tamaki
 
スマートフォンを用いた新生児あやし動作の教示システム
スマートフォンを用いた新生児あやし動作の教示システムスマートフォンを用いた新生児あやし動作の教示システム
スマートフォンを用いた新生児あやし動作の教示システムsugiuralab
 
[DevOpsDays Tokyo 2024] 〜デジタルとアナログのはざまに〜 スマートビルディング爆速開発を支える 自動化テスト戦略
[DevOpsDays Tokyo 2024] 〜デジタルとアナログのはざまに〜 スマートビルディング爆速開発を支える 自動化テスト戦略[DevOpsDays Tokyo 2024] 〜デジタルとアナログのはざまに〜 スマートビルディング爆速開発を支える 自動化テスト戦略
[DevOpsDays Tokyo 2024] 〜デジタルとアナログのはざまに〜 スマートビルディング爆速開発を支える 自動化テスト戦略Ryo Sasaki
 
【早稲田AI研究会 講義資料】3DスキャンとTextTo3Dのツールを知ろう!(Vol.1)
【早稲田AI研究会 講義資料】3DスキャンとTextTo3Dのツールを知ろう!(Vol.1)【早稲田AI研究会 講義資料】3DスキャンとTextTo3Dのツールを知ろう!(Vol.1)
【早稲田AI研究会 講義資料】3DスキャンとTextTo3Dのツールを知ろう!(Vol.1)Hiroki Ichikura
 
SOPを理解する 2024/04/19 の勉強会で発表されたものです
SOPを理解する       2024/04/19 の勉強会で発表されたものですSOPを理解する       2024/04/19 の勉強会で発表されたものです
SOPを理解する 2024/04/19 の勉強会で発表されたものですiPride Co., Ltd.
 
論文紹介:Semantic segmentation using Vision Transformers: A survey
論文紹介:Semantic segmentation using Vision Transformers: A survey論文紹介:Semantic segmentation using Vision Transformers: A survey
論文紹介:Semantic segmentation using Vision Transformers: A surveyToru Tamaki
 
Open Source UN-Conference 2024 Kawagoe - 独自OS「DaisyOS GB」の紹介
Open Source UN-Conference 2024 Kawagoe - 独自OS「DaisyOS GB」の紹介Open Source UN-Conference 2024 Kawagoe - 独自OS「DaisyOS GB」の紹介
Open Source UN-Conference 2024 Kawagoe - 独自OS「DaisyOS GB」の紹介Yuma Ohgami
 
論文紹介:Automated Classification of Model Errors on ImageNet
論文紹介:Automated Classification of Model Errors on ImageNet論文紹介:Automated Classification of Model Errors on ImageNet
論文紹介:Automated Classification of Model Errors on ImageNetToru Tamaki
 
TSAL operation mechanism and circuit diagram.pdf
TSAL operation mechanism and circuit diagram.pdfTSAL operation mechanism and circuit diagram.pdf
TSAL operation mechanism and circuit diagram.pdftaisei2219
 

Dernier (9)

論文紹介:Content-Aware Token Sharing for Efficient Semantic Segmentation With Vis...
論文紹介:Content-Aware Token Sharing for Efficient Semantic Segmentation With Vis...論文紹介:Content-Aware Token Sharing for Efficient Semantic Segmentation With Vis...
論文紹介:Content-Aware Token Sharing for Efficient Semantic Segmentation With Vis...
 
スマートフォンを用いた新生児あやし動作の教示システム
スマートフォンを用いた新生児あやし動作の教示システムスマートフォンを用いた新生児あやし動作の教示システム
スマートフォンを用いた新生児あやし動作の教示システム
 
[DevOpsDays Tokyo 2024] 〜デジタルとアナログのはざまに〜 スマートビルディング爆速開発を支える 自動化テスト戦略
[DevOpsDays Tokyo 2024] 〜デジタルとアナログのはざまに〜 スマートビルディング爆速開発を支える 自動化テスト戦略[DevOpsDays Tokyo 2024] 〜デジタルとアナログのはざまに〜 スマートビルディング爆速開発を支える 自動化テスト戦略
[DevOpsDays Tokyo 2024] 〜デジタルとアナログのはざまに〜 スマートビルディング爆速開発を支える 自動化テスト戦略
 
【早稲田AI研究会 講義資料】3DスキャンとTextTo3Dのツールを知ろう!(Vol.1)
【早稲田AI研究会 講義資料】3DスキャンとTextTo3Dのツールを知ろう!(Vol.1)【早稲田AI研究会 講義資料】3DスキャンとTextTo3Dのツールを知ろう!(Vol.1)
【早稲田AI研究会 講義資料】3DスキャンとTextTo3Dのツールを知ろう!(Vol.1)
 
SOPを理解する 2024/04/19 の勉強会で発表されたものです
SOPを理解する       2024/04/19 の勉強会で発表されたものですSOPを理解する       2024/04/19 の勉強会で発表されたものです
SOPを理解する 2024/04/19 の勉強会で発表されたものです
 
論文紹介:Semantic segmentation using Vision Transformers: A survey
論文紹介:Semantic segmentation using Vision Transformers: A survey論文紹介:Semantic segmentation using Vision Transformers: A survey
論文紹介:Semantic segmentation using Vision Transformers: A survey
 
Open Source UN-Conference 2024 Kawagoe - 独自OS「DaisyOS GB」の紹介
Open Source UN-Conference 2024 Kawagoe - 独自OS「DaisyOS GB」の紹介Open Source UN-Conference 2024 Kawagoe - 独自OS「DaisyOS GB」の紹介
Open Source UN-Conference 2024 Kawagoe - 独自OS「DaisyOS GB」の紹介
 
論文紹介:Automated Classification of Model Errors on ImageNet
論文紹介:Automated Classification of Model Errors on ImageNet論文紹介:Automated Classification of Model Errors on ImageNet
論文紹介:Automated Classification of Model Errors on ImageNet
 
TSAL operation mechanism and circuit diagram.pdf
TSAL operation mechanism and circuit diagram.pdfTSAL operation mechanism and circuit diagram.pdf
TSAL operation mechanism and circuit diagram.pdf
 

En vedette

2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by HubspotMarius Sescu
 
Everything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTEverything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTExpeed Software
 
Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsProduct Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsPixeldarts
 
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthThinkNow
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfmarketingartwork
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024Neil Kimberley
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)contently
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024Albert Qian
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsKurio // The Social Media Age(ncy)
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Search Engine Journal
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summarySpeakerHub
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next Tessa Mero
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentLily Ray
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best PracticesVit Horky
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project managementMindGenius
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...RachelPearson36
 

En vedette (20)

2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot
 
Everything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTEverything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPT
 
Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsProduct Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage Engineerings
 
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental Health
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
 
Skeleton Culture Code
Skeleton Culture CodeSkeleton Culture Code
Skeleton Culture Code
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search Intent
 
How to have difficult conversations
How to have difficult conversations How to have difficult conversations
How to have difficult conversations
 
Introduction to Data Science
Introduction to Data ScienceIntroduction to Data Science
Introduction to Data Science
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best Practices
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project management
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
 

真・聴力検査 HACKS

  • 1. 真・聴力検査 HACKS 社外版 2012/10/24 @nipotan
  • 2. 以前社内で • 「聴力検査 HACKS」というネタで LT • Mac で簡単に聴力検査をしたい • だけど音を鳴らすのって複雑だよね
  • 3. say -v Ralph "poe" #!/bin/sh v=1 while [ $v -le 200 ] do vol=`echo "scale=2; ${v} / 100" | bc | sed -e 's/^./0./g'` echo $vol /usr/bin/osascript -e "set Volume ${vol}" /usr/bin/say -r 250 -v Ralph "poe" v=`expr $v + 1` done
  • 4. まぁ… • 急に作ったネタとは言え、だいぶお粗末 • 音程によって声の人物、発音する単語を変え るのはいかがなものか • 声 ではなく 音 を扱うのに say は不適切 なのでは?
  • 5. 聴力検査 • オージオメーター • 英語で書くと audiometer • 健康診断でお馴染み • 「 ピーピーピー ポーポーポー と音が 鳴ってる間はボタンを押してください」 • もっとオージオメーターを手軽に
  • 6. ポー そして ピー • say で poe とか pee とか変じゃない? • 音程によって低音は Ralph さんとか、高音な ら Ya-Ling さんとか、指名するのはなんか変 • そもそも機械的な音声のピーもポーも音程が 違うだけで同じ音色 • 何故 Ralph は poe と言わされたか?
  • 7. 擬音語、奥深い • カタカナで表現する擬音語 • 子音は attack (立ち上がり) による • 母音は音程による (高 イ→エ→ア→オ→ウ 低) • decay (減衰) は「ン」で表現 • Wikipedia の「子音」の項見るとすごい ※個人の感想であり、効果・効能を示すものではありません
  • 8. 擬音語、奥深い • サイレン「ピーポーピーポー」時報「ピ、ピ、 ピ、ポーン」鐘「キンコンカンコン」 • だいたいこの法則に則ってる • 「ノーシンピュア」の CM でアッキーナが 最後に言う「ポンピーン」は唯一例外 • 字が違うが、音程違いだけど同じ音なはず ※個人の感想であり、効果・効能を示すものではありません
  • 9. 人間の口腔は複雑 • 声帯から出る音声は同じでも、口腔の形状で 響き (母音) がかわる • イコライザ、トーンカーブ的な役割 • 人間の音声以外は口腔を介していない ※個人の感想であり、効果・効能を示すものではありません
  • 10. 人間の口腔は複雑 • ボコーダー、トーキングモジュレータ、ワウ ペダル、ワウワウミュート等は人間の口腔に よる音色変化をシミュレート • ボコーダー: YMO「Technopolis」 • トーキングモジュレータ: BON JOVI「Livin On a Prayer」、同じ BON JOVI で、 な かやまきんに君がパスタに粉チーズかける時の BGM「It s My Life」 • ワウペダル: Jimi Hendrix「Voodoo Child」、B z 松本孝弘の音作り (マニアック) • ワウワウミュート: Pee Wee Hunt「Somebody Stole My Gal」(吉本新喜劇のテーマ) ※個人の感想であり、効果・効能を示すものではありません
  • 11. Mac で音を鳴らす • say はやめて、純粋な音を鳴らす • Perl で .wav (WAVE) ファイルを作ろう • データ形式について軽く調べれば出来る • ちなみに音に関しては完全にド素人。この ネタのために、調べたり頭で考えながら 作った資料なのであんまり細かいこと言わ ないでください ※個人の感想であり、効果・効能を示すものではありません
  • 12. CD 音質 • 44100 Hz, 16bit, ステレオ • 秒間 44100 サンプル • 1 サンプル 16bit → 2 bytes • ステレオはサンプルが左右交互に 2 つ • block size は 2 bytes x 2 = 4 bytes • 44100 (sample) x 4 (bytes) =176,400 bytes/sec ( 172.27KB 1.35Mbps)
  • 13. WAVE データ形式 • RIFF (Resource Interchange File Format) という汎用メタファイル形式 • RIFF ヘッダと RIFF データからなる • WAVE データは RIFF データ内の WAVE ヘッダとサブチャンクから構成
  • 14. WAVE データ形式 • 格納データはリトルエンディアン形式 • Apple が採用する AIFF (Audio Interchange File Format) は似たフォーマットで格納デー タはビッグエンディアン形式 • そもそも RIFF は AIFF を元に作られた?
  • 15. WAVE データ 内容 バイト数 RIFF ヘッダ 8 WAVE ヘッダ WAVE 4 fmt チャンク 24∼ data チャンク - あくまで、音を鳴らすための最低限
  • 16. RIFF ヘッダ 内容 バイト数 RIFF 識別子 RIFF 4 これより後ろのデータサイズ 4 (合計サイズ -8)
  • 17. WAVE ヘッダ 内容 バイト数 WAVE 識別子 WAVE 4
  • 18. fmt チャンク 内容 バイト数 fmt 識別子 fmt 4 fmt チャンクの これより後ろのデータサイズ 4 フォーマット ID (リニア PCM = 1) 2 チャンネル数 (モノ:1 ステレオ: 2) 2 サンプリングレート (Hz) 4 データ速度 (サンプリングレート x block size) 4 block size 2 bit 数 2
  • 19. data チャンク 内容 バイト数 data 識別子 data 4 data チャンクの 4 これより後ろのデータサイズ 音声データ -
  • 20. 音声データ 内容 バイト数 左チャンネルのサンプル 2 右チャンネルのサンプル 2 ↑これが 1 ブロック 1 秒あたり 44100 ブロック
  • 21. 音の基礎 • 440Hz (秒間 440 回振幅) の音はラ (A4) • 半分の 220Hz、倍の 880Hz もラ (A3, A5) • A3∼A5 は用紙サイズではなく A がラを、 後ろの数字がオクターブを表す • MIDI データだとオクターブが 1 つ下の扱い
  • 22. 音の基礎 • オクターブ間の周波数を 12 分割したのが音 階 ((十二)平均律) で、世の中の音楽のデファ クト • 和声で平均律の不自然さに異を唱える思想 もあり。「音律」で Wikipedia • 振幅の幅が音量 • 振幅の形が音色
  • 23. 振幅の形 (波形) • 代表: 正弦波 (sine)、矩形波 (square)、三角 波 (triangle)、のこぎり波 (sawtooth)
  • 24. 楽器の音色の違い • 波形の違い • attack, decay の違い • 基音 (fundamental tone) と倍音 (harmonics) の音量と組み合わせの違い • トーンの違い ※個人の感想であり、効果・効能を示すものではありません
  • 25. 純音 • 楽音と違い、オージオメーターは「純音」 • 倍音を一切含まない正弦波 • 自然界には存在しない音 (口笛、音叉、クリ スタルガラス楽器演奏が近い) ※個人の感想であり、効果・効能を示すものではありません
  • 26. 純音 • アナログでは、ウィーンブリッジ発振回路 (Wien bridge oscillator) で実現可能 • デジタルでは量子化による誤差が生じる • 「完全な正弦波は作れない」 • サンプリングレート、量子化ビット数を上 げることで近似的な音は作れる ※個人の感想であり、効果・効能を示すものではありません
  • 27. オージオメータ仕様 • 125Hz, 250Hz, 500Hz, 1000Hz, 2000Hz, 4000Hz, 8000Hz を出力する • シの音 (123.47Hz, 246.94Hz, 493.88Hz, 987.76Hz ...) に近い • 音が鳴ってる箇所、無音の箇所の繰り返し • 左右で鳴り分け (ステレオ)
  • 28. WAVE で作る純音 • 音声データ生成における Hello World (多分) • 正弦波を 16bit で表現する ※個人の感想であり、効果・効能を示すものではありません
  • 29. WAVE で作る純音 sub make_sine {     my($hz, $sec, $lvol, $rvol) = @_;     my $maxno = 2 ** 16 / 2 - 1; # 32767     $lvol = $lvol / 100 * $maxno;     $rvol = $rvol / 100 * $maxno;     my $length = 44100 * $sec;     my $sound = '';     for my $pos (1 .. $length) {         my $val = sin 2 * 3.14 * $hz * ($pos / 44100);         $sound .= pack 'v', $val * $lvol; # left         $sound .= pack 'v', $val * $rvol; # right     }     return $sound; }
  • 30. WAVE で作る無音 sub make_silent {     my $sec = shift;     my $length = 44100 * $sec;     my $sound = '';     for my $pos (1 .. $length) {         $sound .= "0" x 4;     }     return $sound; }
  • 31. 純音無音の繰り返し sub audiometer {     my($lr, $oct) = @_;     my $hz = 500 * 2 ** ($oct - 3);     my $data = '';     for my $vol (1 .. 20) {         my @vol_args = uc($lr) eq 'L' ? ($vol, 0) : (0, $vol);         $data .= make_sine($hz, 0.3, @vol_args);         $data .= make_silent(0.2);     }     return $data; }
  • 32. 忘れないで、ヘッダ my $header = riff_header(length $data); sub riff_header {     my $size = shift;     my $header = 'RIFF'; # RIFF header     $header .= pack 'V', $size + 36; # following data size     $header .= 'WAVE'; # WAVE header     $header .= 'fmt '; # fmt header     $header .= pack 'V', 16; # format chunk size     $header .= pack 'v', 1; # format id (PCM = 1)     $header .= pack 'v', 2; # monaural = 1, stereo = 2     $header .= pack 'V', 44100; # sampling rate (44.1kHz)     $header .= pack 'V', 44100 * 4; # byte/sec     $header .= pack 'v', 4; # block size (16bit stereo)     $header .= pack 'v', 16; # bit/sample     $header .= 'data'; # data header     $header .= pack 'V', $size; # data chunk size     return $header; }
  • 33. お洒落に PSGI で my $app = sub {     my $env = shift;     my @path = $env->{REQUEST_URI} =~ m{^/([lr])/([1-7])/?$}i;     die "invalid path $env->{REQUEST_URI}" unless @path == 2;     my $wave = audiometer(@path);     return [         200,         [             'Content-Type' => 'audio/x-wav',             'Content-Length' => length($wave) + 44,         ],         [             riff_header(length $wave),             $wave,         ],     ]; };
  • 34. DEMO
  • 35. 応用: モスキート音 sub mosquito { return make_sine(17000, 10, 100, 100) } • 17kHz 以上の音はモスキート音 • 若者には聞こえるらしいぜ • はぁ、どうせ聞こえねーし ※個人の感想であり、効果・効能を示すものではありません
  • 36. 応用: 簡易シーケンサ sub tone_to_hz {     my $tone = shift;     my($scale, $shift, $octave) = $tone =~ / ^ ([A-G]) # A-G ([-+b#]?) # -, +, b, # ([1-9]?) # 1-9 $ /x;     return 0 unless $scale;     my %tone_index = (         C => -9, D => -7, E => -5, F => -4, G => -2, A => 0, B => 2,     );     my $index = $tone_index{$scale};     if ($shift) {         my $num = $shift eq '+' || $shift eq '#' ? 1 : -1;         $index += $num;     }     if ($octave && $octave != 3) {         $index += ($octave - 3) * 12;     }     return 440 * (2 ** ($index / 12)); }
  • 37. 応用: 簡易シーケンサ sub sequence {     my $bpm = shift;     my $crotchet = 60 / $bpm;     my $seconds = +{         16 => $crotchet / 4,         8 => $crotchet / 2,         4 => $crotchet,         2 => $crotchet * 2,         1 => $crotchet * 4,     };     my $wave = '';     for my $data (@_) {         my($tone, $len, $vol) = @$data;         $vol ||= 80;         my $sec = 0;         for my $note (split /-/, $len) {             my $dotted = $tone =~ s/.$// ? 1 : 0;             $sec += $seconds->{$note} * ($dotted ? 1.5 : 1);         }         if ($tone eq '-') {             $wave .= make_silent($sec);             next;         }         $wave .= make_sine(tone_to_hz($tone), $sec, $vol, $vol);     }     return $wave; }
  • 38. 応用: 簡易シーケンサ sub heavy_rotation {         ['C#4', 4], # ン     my $bpm = shift;         ['C#4', 4], # ガ     my $crotchet = 60 / $bpm;     return sequence(         ['A3', 4], # ン         $bpm,         ['F#3', 4], # な         ['E3', 4], # I         ['F#3', 4], # want         ['F#3', 4], # っ         ['G#3', '1-4'], # you         ['G#3', 4], # て         ['-', 4],         ['A3', 4], # る         ['E3', 4], # I         ['F#3', 4], # need         ['B3', 4], # mu         ['G#3', '1-4'], # you         ['B3', 4], # -         ['-', 4],         ['B3', 4], # si         ['E3', 4], # I         ['G#3', 4], # -         ['F#3', 4], # love         ['E3', 2], # c         ['G#3', '1-4'], # you         ['-', 4],         ['-', 4],         ['G#3', 4], # hea         ['G#3', 4], # あ         ['A3', 2], # vy         ['C#3', 2], # -         ['A3', 4], # た         ['E3', 4], # ro         ['B3', 2], # ま         ['D#3', 4], # -         ['G#3', 2], # の         ['C#3', 4], # ta         ['D#3', 4], # -         ['F#3', 2], # な         ['E3', 2], # tion         ['E3', 2], # か     ); }         ['C#4', 4], # ガ
  • 39. この聴力検査方法 • 厳密な聴力の検査には向かない • 再生デバイス側でボリュームコントロール 可能 • 音波への変換装置の個体差 • あくまで簡易的な検査にとどめましょう • 耳の異常を感じたら、早めに耳鼻科へ
  • 40. まとめ • あくまで、音を扱ってみただけです • でも音を扱うのは基本がわかればちょっと 楽しくなってくる