Unity Community


Page 1 of 2 12 LastLast
Results 1 to 20 of 31

  1. Location
    Sacramento, CA. USA
    Posts
    106

    Blow detection (Using iOS Microphone)

    Anyone out there have any working scripts to detect Microphone Input levels for iOS? I need to simply detect how hard the player is blowing in to the mic. Anyone? Anyone have a good idea?
    Daniel Monroe
    Unity 3D Developer for
    Logistic Win Software
    www.LogisticWin.com


  2. Location
    Sacramento, CA. USA
    Posts
    106
    Daniel Monroe
    Unity 3D Developer for
    Logistic Win Software
    www.LogisticWin.com


  3. Location
    Norway
    Posts
    152
    There's microphone recording in 3.5, but I don't know if it works with iphone (see Microphone class in docs). It also looks like you have to record a clip before you can analyze it. If that doesn't work for you I guess you'd have to make your own plugin to interface with the iphone microphone.

    Each sample in the recorded audio will correspond to the sound pressure level at a specific time, so just look for high values to detect a hard blow. If you need to look for a high sound pressure over time, keep in mind that sound pressure is a logarithmic scale (decibel).


  4. Location
    Sacramento, CA. USA
    Posts
    106
    One of the new features in 3.5 is iPhone microphone support... has anyone done any work to detect audio input from Microphones before with Unity?
    Daniel Monroe
    Unity 3D Developer for
    Logistic Win Software
    www.LogisticWin.com


  5. Posts
    14
    Since I read your last reply I have been look for the Microphone class in the docs (for about an hour), but cannot find it. Could you post a link please? Sorry, I feel like this should be simple.


  6. Location
    Australia
    Posts
    144
    I notice that the Microphone functions have a set number of seconds of recording. What if you don't want to store anything but just stream and effect the microphone audio?


  7. Location
    Tokyo
    Posts
    792
    Learn Harmonica Faster! HarpNinja
    Develop Your Ears with Chordskilz - the Music Ear Training Game.


  8. Location
    Unity HQ
    Posts
    123
    Quote Originally Posted by Logic Twilight View Post
    Anyone out there have any working scripts to detect Microphone Input levels for iOS? I need to simply detect how hard the player is blowing in to the mic. Anyone? Anyone have a good idea?
    From the top of my head:
    Code:  
    1. {
    2.   clip.GetOutputData(...); <-- the input levels
    3. }
    Søren Christiansen
    Audio Programmer


  9. Posts
    14
    In theory soren's example should work, however it's not so easy.

    Microphone.Start() records the input data to a clip (for a set amount of seconds), and it's AudioSource object (not the clip itself) can be analysed with the GetOutputData function. This is fine if you want to record for a while, and analyse later. However, I am looking to do real-time interaction with the microphone.

    I have tried start and finish recording between update calls (and to run GetOutputData in-between), but I am sure this is a bad approach.


    Also Pitch Poll looks fantastic (especially for only a slim $10), but I am just looking to read frequency, volume, and pitch and that's it. I don't really want ALL of the other great stuff that comes with it..


  10. Location
    Unity HQ
    Posts
    123
    Quote Originally Posted by Riro View Post
    In theory soren's example should work, however it's not so easy.

    Microphone.Start() records the input data to a clip (for a set amount of seconds), and it's AudioSource object (not the clip itself) can be analysed with the GetOutputData function. This is fine if you want to record for a while, and analyse later. However, I am looking to do real-time interaction with the microphone.
    Right, you should use clip.GetData() instead. Or you could just play the AudioSource when GetPosition>0. Then you get it realtime with GetOutputData. (if you use audio.clip = Microphone.Start() and you play the AudioSource).
    Last edited by soren; 01-16-2012 at 03:40 AM.
    Søren Christiansen
    Audio Programmer


  11. Posts
    14
    Ok, this is starting to make more sense. I have got this script so far... (I am not very good at audio, so forgive me for mistakes).

    Code:  
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. public class MicHandle : MonoBehaviour {
    5.  
    6.   public GameObject display;        // GUIText for displaying results
    7.  
    8.   private int sampleCount = 1024;      // Sample Count.
    9.   private float refValue = 0.1f;    // RMS value for 0 dB.
    10.   private float threshold = 0.02f;  // Minimum amplitude to extract pitch (recieve anything)
    11.   private float rmsValue;           // Volume in RMS
    12.   private float dbValue;            // Volume in DB
    13.   private float pitchValue;         // Pitch - Hz (is this frequency?)
    14.  
    15.   private float[] samples;          // Samples
    16.   private float[] spectrum;         // Spectrum
    17.  
    18.   public void Start () {
    19.  
    20.     samples = new float[sampleCount];
    21.     spectrum = new float[sampleCount];
    22.  
    23.     // This starts the mic, for 999 seconds, recording at 48000 hz. I am unsure of how to avoid this hack.
    24.     audio.clip = Microphone.Start("Built-in Microphone", false, 999, 48000);
    25.     audio.Play();
    26.   }
    27.  
    28.   public void Update () {
    29.  
    30.     // Le big cheese doing its thing.
    31.     AnalyzeSound();
    32.  
    33.     if (display){
    34.       display.guiText.text = "RMS: " + rmsValue.ToString("F2") + " (" + dbValue.ToString("F1") + " dB)\n" + "Pitch: " + pitchValue.ToString("F0") + " Hz";
    35.     } else {
    36.       Debug.Log("Display broke somewhere");
    37.     }
    38.   }
    39.  
    40.   private void AnalyzeSound() {
    41.     audio.GetOutputData(samples, 0); // Get all of our samples from the mic.
    42.  
    43.     // Sums squared samples
    44.     float sum = 0;
    45.     for (int i = 0; i < sampleCount; i++){
    46.       sum += Mathf.Pow(samples[i], 2);
    47.     }
    48.  
    49.     rmsValue = Mathf.Sqrt(sum/sampleCount);          // RMS is the square root of the average value of the samples.
    50.     dbValue = 20*Mathf.Log10(rmsValue/refValue);  // dB
    51.  
    52.     // Clamp it to -160dB min
    53.     if (dbValue < -160) {
    54.       dbValue = -160;
    55.     }
    56.  
    57.     // Gets the sound spectrum.
    58.     audio.GetSpectrumData(spectrum, 0, FFTWindow.BlackmanHarris);
    59.     float maxV = 0;
    60.     int maxN = 0;
    61.  
    62.     // Find the highest sample.
    63.     for (int i = 0; i < sampleCount; i++){
    64.       if (spectrum[i] > maxV && spectrum[i] > threshold){
    65.         maxV = spectrum[i];
    66.         maxN = i; // maxN is the index of max
    67.       }
    68.     }
    69.  
    70.     // Pass the index to a float variable
    71.     float freqN = maxN;
    72.  
    73.     // Interpolate index using neighbours
    74.     if (maxN > 0 && maxN < sampleCount - 1) {
    75.       float dL = spectrum[maxN-1] / spectrum[maxN];
    76.       float dR = spectrum[maxN+1] / spectrum[maxN];
    77.       freqN += 0.5f * (dR * dR - dL * dL);
    78.     }
    79.  
    80.     // Convert index to frequency
    81.     pitchValue = freqN * 24000 / sampleCount;
    82.   }
    83.  
    84. }

    I got the AnalyzeSound() function from here.

    I just gave this a few tests, and it seems to work ideally 4 out of 10 times (6 times no audio data is shown at all, maybe the mic doesn't turn on properly?). There must be something unstable in that code, but I am a little unsure of what it is.


  12. Location
    Unity HQ
    Posts
    123
    Quote Originally Posted by Riro View Post
    I just gave this a few tests, and it seems to work ideally 4 out of 10 times (6 times no audio data is shown at all, maybe the mic doesn't turn on properly?). There must be something unstable in that code, but I am a little unsure of what it is.
    You have to wait for Microphone.GetPosition > 0. Then it should work all the time.
    Søren Christiansen
    Audio Programmer


  13. Posts
    14
    Quote Originally Posted by soren View Post
    You have to wait for Microphone.GetPosition > 0. Then it should work all the time.
    Ah I see!

    I was getting stuck because calling audio.Play() every frame seems to stop the GetOutputData from working. I will have play around with things and post back any success / better code I have.

    Thanks dude


  14. Posts
    14
    So now I have a (slight) new problem.

    It is correct that waiting for Microphone.GetPosition > 0 ensures it never fails. However, this causes about a 1 second delay between the input and output of that clip. Is there some way I can Play() the clip part way through... say at the Microphone position?


  15. Posts
    14
    Hello, hello, I have mostly success. Check it out, feedback welcome.

    The code can detect a blow, and won't trigger from a whistle, click, tap, hum etc. It does trigger if I drag my laptop over some material, like the couch, as the sound is very similar. Let me know what you think / tweak anything you see fit.

    An example project where you can blow up a sphere, and see some stats is ready to go if anyone wants it. Here's the code.

    Code:  
    1. using UnityEngine;
    2. using System.Collections;
    3. using System.Collections.Generic;
    4.  
    5. public class MicHandle : MonoBehaviour {
    6.  
    7.   private const int FREQUENCY = 48000;    // Wavelength, I think.
    8.   private const int SAMPLECOUNT = 1024;   // Sample Count.
    9.   private const float REFVALUE = 0.1f;    // RMS value for 0 dB.
    10.   private const float THRESHOLD = 0.02f;  // Minimum amplitude to extract pitch (recieve anything)
    11.   private const float ALPHA = 0.05f;      // The alpha for the low pass filter (I don't really understand this).
    12.  
    13.   public GameObject resultDisplay;   // GUIText for displaying results
    14.   public GameObject blowDisplay;     // GUIText for displaying blow or not blow.
    15.   public int recordedLength = 50;    // How many previous frames of sound are analyzed.
    16.   public int requiedBlowTime = 4;    // How long a blow must last to be classified as a blow (and not a sigh for instance).
    17.   public int clamp = 160;            // Used to clamp dB (I don't really understand this either).
    18.  
    19.   private float rmsValue;            // Volume in RMS
    20.   private float dbValue;             // Volume in DB
    21.   private float pitchValue;          // Pitch - Hz (is this frequency?)
    22.   private int blowingTime;           // How long each blow has lasted
    23.  
    24.   private float lowPassResults;      // Low Pass Filter result
    25.   private float peakPowerForChannel; //
    26.  
    27.   private float[] samples;           // Samples
    28.   private float[] spectrum;          // Spectrum
    29.   private List<float> dbValues;      // Used to average recent volume.
    30.   private List<float> pitchValues;   // Used to average recent pitch.
    31.  
    32.   public void Start () {
    33.     samples = new float[SAMPLECOUNT];
    34.     spectrum = new float[SAMPLECOUNT];
    35.     dbValues = new List<float>();
    36.     pitchValues = new List<float>();
    37.  
    38.     StartMicListener();
    39.   }
    40.  
    41.   public void Update () {
    42.  
    43.     // If the audio has stopped playing, this will restart the mic play the clip.
    44.     if (!audio.isPlaying) {
    45.       StartMicListener();
    46.     }
    47.  
    48.     // Gets volume and pitch values
    49.     AnalyzeSound();
    50.  
    51.     // Runs a series of algorithms to decide whether a blow is occuring.
    52.     DeriveBlow();
    53.  
    54.     // Update the meter display.
    55.     if (resultDisplay){
    56.       resultDisplay.guiText.text = "RMS: " + rmsValue.ToString("F2") + " (" + dbValue.ToString("F1") + " dB)\n" + "Pitch: " + pitchValue.ToString("F0") + " Hz";
    57.     }
    58.   }
    59.  
    60.   /// Starts the Mic, and plays the audio back in (near) real-time.
    61.   private void StartMicListener() {
    62.     audio.clip = Microphone.Start("Built-in Microphone", true, 999, FREQUENCY);
    63.     // HACK - Forces the function to wait until the microphone has started, before moving onto the play function.
    64.     while (!(Microphone.GetPosition("Built-in Microphone") > 0)) {
    65.     } audio.Play();
    66.   }
    67.  
    68.   /// Credits to aldonaletto for the function, http://goo.gl/VGwKt
    69.   /// Analyzes the sound, to get volume and pitch values.
    70.   private void AnalyzeSound() {
    71.  
    72.     // Get all of our samples from the mic.
    73.  
    74.     // Sums squared samples
    75.     float sum = 0;
    76.     for (int i = 0; i < SAMPLECOUNT; i++){
    77.       sum += Mathf.Pow(samples[i], 2);
    78.     }
    79.  
    80.     // RMS is the square root of the average value of the samples.
    81.     rmsValue = Mathf.Sqrt(sum / SAMPLECOUNT);
    82.     dbValue = 20 * Mathf.Log10(rmsValue / REFVALUE);
    83.  
    84.     // Clamp it to {clamp} min
    85.     if (dbValue < -clamp) {
    86.       dbValue = -clamp;
    87.     }
    88.  
    89.     // Gets the sound spectrum.
    90.     audio.GetSpectrumData(spectrum, 0, FFTWindow.BlackmanHarris);
    91.     float maxV = 0;
    92.     int maxN = 0;
    93.  
    94.     // Find the highest sample.
    95.     for (int i = 0; i < SAMPLECOUNT; i++){
    96.       if (spectrum[i] > maxV && spectrum[i] > THRESHOLD){
    97.         maxV = spectrum[i];
    98.         maxN = i; // maxN is the index of max
    99.       }
    100.     }
    101.  
    102.     // Pass the index to a float variable
    103.     float freqN = maxN;
    104.  
    105.     // Interpolate index using neighbours
    106.     if (maxN > 0 && maxN < SAMPLECOUNT - 1) {
    107.       float dL = spectrum[maxN-1] / spectrum[maxN];
    108.       float dR = spectrum[maxN+1] / spectrum[maxN];
    109.       freqN += 0.5f * (dR * dR - dL * dL);
    110.     }
    111.  
    112.     // Convert index to frequency
    113.     pitchValue = freqN * 24000 / SAMPLECOUNT;
    114.   }
    115.  
    116.   private void DeriveBlow() {
    117.  
    118.     UpdateRecords(dbValue, dbValues);
    119.     UpdateRecords(pitchValue, pitchValues);
    120.  
    121.     // Find the average pitch in our records (used to decipher against whistles, clicks, etc).
    122.     float sumPitch = 0;
    123.     foreach (float num in pitchValues) {
    124.       sumPitch += num;
    125.     }
    126.     sumPitch /= pitchValues.Count;
    127.  
    128.     // Run our low pass filter.
    129.     lowPassResults = LowPassFilter(dbValue);
    130.  
    131.     // Decides whether this instance of the result could be a blow or not.
    132.     if (lowPassResults > -30 && sumPitch == 0) {
    133.       blowingTime += 1;
    134.     } else {
    135.       blowingTime = 0;
    136.     }
    137.  
    138.     // Once enough successful blows have occured over the previous frames (requiredBlowTime), the blow is triggered.
    139.     // This example says "blowing", or "not blowing", and also blows up a sphere.
    140.     if (blowingTime > requiedBlowTime) {
    141.       blowDisplay.guiText.text = "Blowing";
    142.       GameObject.FindGameObjectWithTag("Meter").transform.localScale *= 1.012f;
    143.     } else {
    144.       blowDisplay.guiText.text = "Not blowing";
    145.       GameObject.FindGameObjectWithTag("Meter").transform.localScale *= 0.999f;
    146.     }
    147.   }
    148.  
    149.   // Updates a record, by removing the oldest entry and adding the newest value (val).
    150.   private void UpdateRecords(float val, List<float> record) {
    151.     if (record.Count > recordedLength) {
    152.       record.RemoveAt(0);
    153.     }
    154.     record.Add(val);
    155.   }
    156.  
    157.   /// Gives a result (I don't really understand this yet) based on the peak volume of the record
    158.   /// and the previous low pass results.
    159.   private float LowPassFilter(float peakVolume) {
    160.     return ALPHA * peakVolume + (1.0f - ALPHA) * lowPassResults;
    161.   }
    162. }

    I will be posting a tutorial up once I get this code working nicely, over here http://goo.gl/YU0vj.


  16. Location
    Unity HQ
    Posts
    123
    Quote Originally Posted by Riro View Post
    Hello, hello, I have mostly success. Check it out, feedback welcome.

    The code can detect a blow, and won't trigger from a whistle, click, tap, hum etc. It does trigger if I drag my laptop over some material, like the couch, as the sound is very similar. Let me know what you think / tweak anything you see fit.

    An example project where you can blow up a sphere, and see some stats is ready to go if anyone wants it. Here's the code.

    Code:  
    1. using UnityEngine;
    2. using System.Collections;
    3. using System.Collections.Generic;
    4.  
    5. public class MicHandle : MonoBehaviour {
    6.  
    7.   private const int FREQUENCY = 48000;    // Wavelength, I think.
    8.   private const int SAMPLECOUNT = 1024;   // Sample Count.
    9.   private const float REFVALUE = 0.1f;    // RMS value for 0 dB.
    10.   private const float THRESHOLD = 0.02f;  // Minimum amplitude to extract pitch (recieve anything)
    11.   private const float ALPHA = 0.05f;      // The alpha for the low pass filter (I don't really understand this).
    12.  
    13.   public GameObject resultDisplay;   // GUIText for displaying results
    14.   public GameObject blowDisplay;     // GUIText for displaying blow or not blow.
    15.   public int recordedLength = 50;    // How many previous frames of sound are analyzed.
    16.   public int requiedBlowTime = 4;    // How long a blow must last to be classified as a blow (and not a sigh for instance).
    17.   public int clamp = 160;            // Used to clamp dB (I don't really understand this either).
    18.  
    19.   private float rmsValue;            // Volume in RMS
    20.   private float dbValue;             // Volume in DB
    21.   private float pitchValue;          // Pitch - Hz (is this frequency?)
    22.   private int blowingTime;           // How long each blow has lasted
    23.  
    24.   private float lowPassResults;      // Low Pass Filter result
    25.   private float peakPowerForChannel; //
    26.  
    27.   private float[] samples;           // Samples
    28.   private float[] spectrum;          // Spectrum
    29.   private List<float> dbValues;      // Used to average recent volume.
    30.   private List<float> pitchValues;   // Used to average recent pitch.
    31.  
    32.   public void Start () {
    33.     samples = new float[SAMPLECOUNT];
    34.     spectrum = new float[SAMPLECOUNT];
    35.     dbValues = new List<float>();
    36.     pitchValues = new List<float>();
    37.  
    38.     StartMicListener();
    39.   }
    40.  
    41.   public void Update () {
    42.  
    43.     // If the audio has stopped playing, this will restart the mic play the clip.
    44.     if (!audio.isPlaying) {
    45.       StartMicListener();
    46.     }
    47.  
    48.     // Gets volume and pitch values
    49.     AnalyzeSound();
    50.  
    51.     // Runs a series of algorithms to decide whether a blow is occuring.
    52.     DeriveBlow();
    53.  
    54.     // Update the meter display.
    55.     if (resultDisplay){
    56.       resultDisplay.guiText.text = "RMS: " + rmsValue.ToString("F2") + " (" + dbValue.ToString("F1") + " dB)\n" + "Pitch: " + pitchValue.ToString("F0") + " Hz";
    57.     }
    58.   }
    59.  
    60.   /// Starts the Mic, and plays the audio back in (near) real-time.
    61.   private void StartMicListener() {
    62.     audio.clip = Microphone.Start("Built-in Microphone", true, 999, FREQUENCY);
    63.     // HACK - Forces the function to wait until the microphone has started, before moving onto the play function.
    64.     while (!(Microphone.GetPosition("Built-in Microphone") > 0)) {
    65.     } audio.Play();
    66.   }
    67.  
    68.   /// Credits to aldonaletto for the function, http://goo.gl/VGwKt
    69.   /// Analyzes the sound, to get volume and pitch values.
    70.   private void AnalyzeSound() {
    71.  
    72.     // Get all of our samples from the mic.
    73.  
    74.     // Sums squared samples
    75.     float sum = 0;
    76.     for (int i = 0; i < SAMPLECOUNT; i++){
    77.       sum += Mathf.Pow(samples[i], 2);
    78.     }
    79.  
    80.     // RMS is the square root of the average value of the samples.
    81.     rmsValue = Mathf.Sqrt(sum / SAMPLECOUNT);
    82.     dbValue = 20 * Mathf.Log10(rmsValue / REFVALUE);
    83.  
    84.     // Clamp it to {clamp} min
    85.     if (dbValue < -clamp) {
    86.       dbValue = -clamp;
    87.     }
    88.  
    89.     // Gets the sound spectrum.
    90.     audio.GetSpectrumData(spectrum, 0, FFTWindow.BlackmanHarris);
    91.     float maxV = 0;
    92.     int maxN = 0;
    93.  
    94.     // Find the highest sample.
    95.     for (int i = 0; i < SAMPLECOUNT; i++){
    96.       if (spectrum[i] > maxV && spectrum[i] > THRESHOLD){
    97.         maxV = spectrum[i];
    98.         maxN = i; // maxN is the index of max
    99.       }
    100.     }
    101.  
    102.     // Pass the index to a float variable
    103.     float freqN = maxN;
    104.  
    105.     // Interpolate index using neighbours
    106.     if (maxN > 0 && maxN < SAMPLECOUNT - 1) {
    107.       float dL = spectrum[maxN-1] / spectrum[maxN];
    108.       float dR = spectrum[maxN+1] / spectrum[maxN];
    109.       freqN += 0.5f * (dR * dR - dL * dL);
    110.     }
    111.  
    112.     // Convert index to frequency
    113.     pitchValue = freqN * 24000 / SAMPLECOUNT;
    114.   }
    115.  
    116.   private void DeriveBlow() {
    117.  
    118.     UpdateRecords(dbValue, dbValues);
    119.     UpdateRecords(pitchValue, pitchValues);
    120.  
    121.     // Find the average pitch in our records (used to decipher against whistles, clicks, etc).
    122.     float sumPitch = 0;
    123.     foreach (float num in pitchValues) {
    124.       sumPitch += num;
    125.     }
    126.     sumPitch /= pitchValues.Count;
    127.  
    128.     // Run our low pass filter.
    129.     lowPassResults = LowPassFilter(dbValue);
    130.  
    131.     // Decides whether this instance of the result could be a blow or not.
    132.     if (lowPassResults > -30 && sumPitch == 0) {
    133.       blowingTime += 1;
    134.     } else {
    135.       blowingTime = 0;
    136.     }
    137.  
    138.     // Once enough successful blows have occured over the previous frames (requiredBlowTime), the blow is triggered.
    139.     // This example says "blowing", or "not blowing", and also blows up a sphere.
    140.     if (blowingTime > requiedBlowTime) {
    141.       blowDisplay.guiText.text = "Blowing";
    142.       GameObject.FindGameObjectWithTag("Meter").transform.localScale *= 1.012f;
    143.     } else {
    144.       blowDisplay.guiText.text = "Not blowing";
    145.       GameObject.FindGameObjectWithTag("Meter").transform.localScale *= 0.999f;
    146.     }
    147.   }
    148.  
    149.   // Updates a record, by removing the oldest entry and adding the newest value (val).
    150.   private void UpdateRecords(float val, List<float> record) {
    151.     if (record.Count > recordedLength) {
    152.       record.RemoveAt(0);
    153.     }
    154.     record.Add(val);
    155.   }
    156.  
    157.   /// Gives a result (I don't really understand this yet) based on the peak volume of the record
    158.   /// and the previous low pass results.
    159.   private float LowPassFilter(float peakVolume) {
    160.     return ALPHA * peakVolume + (1.0f - ALPHA) * lowPassResults;
    161.   }
    162. }

    I will be posting a tutorial up once I get this code working nicely, over here http://goo.gl/YU0vj.
    Cool!
    You should use AudioSettings.outputSampleRate to get the right frequency instead of hardcoding it (it's 24000 on iOS by default)
    Søren Christiansen
    Audio Programmer


  17. Location
    Australia
    Posts
    144
    Nice work. But does setting the Start function to 999 seconds actually record 999 seconds worth of audio into RAM? What happens if you want it to go indefinately?


  18. Posts
    14
    Hey thanks, glad to see you guys like it

    Quote Originally Posted by Vectrex View Post
    Nice work. But does setting the Start function to 999 seconds actually record 999 seconds worth of audio into RAM? What happens if you want it to go indefinately?
    I am rather concerned about this. Here is the problem:

    Microphone.Start takes four arguments - microphone name, loop recording (bool), record time in seconds, and frequency. If we set a looping record for 10 seconds, Unity will record as normal for however long (I tested this). However at the end of each period (10 seconds), the recording must be stopped, the clip deleted (ram freed up), a new clip made, and finally the recording begun again. This leds to a very short pause (about 1 / 20 of a second).

    So yes, the 999 seconds worth is ALL stored into the ram, which I know is silly the script is still at a testing stage. There is no way, within Unity, to just turn the Mic on and extract data. I am sure this will be added by the Unity team soon, but until then I might just use a 60 second clip (like below) and deal with the short pauses. I'm not sure... any ideas?

    Code:  
    1. Microphone.Start("Built-in Microphone", true, 60, AudioSettings.outputSampleRate); // Thanks Soren!


  19. Location
    Unity HQ
    Posts
    123
    Quote Originally Posted by Riro View Post
    However at the end of each period (10 seconds), the recording must be stopped, the clip deleted (ram freed up), a new clip made, and finally the recording begun again. This leds to a very short pause (about 1 / 20 of a second).
    This doesn't seem right? Who's deleting the clip and make a new one?
    For your pitch detection you probably only need 0.5 s worth of data right? So why don't you just a 0.5s long buffer with Microphone.Start and set it to loop? A then perform your fourier transform on that data? (spectrum)
    Søren Christiansen
    Audio Programmer


  20. Location
    Turkey
    Posts
    1,925
    a game called iBlow ?? No, thanks

Page 1 of 2 12 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •