Oppure

Loading
30/10/10 20:57
Salve, avevo trovato questo codice nei forum americani che ora non mi ricordo qual'è.
Mi dite come posso fare ad registrare un file wave ad 128kbps e 8 mhz.??
Ho il seguente codice:

   public void OpenMic()
        {
            int sampleResolution = 16;
            int sampleRate = 44100;
            int channels = 2;

            mciSendString("open new Type waveaudio Alias recsound", null, 0, IntPtr.Zero);
            mciSendString("set recsound bitspersample " + sampleResolution.ToString(), null, 0, IntPtr.Zero);
            mciSendString("set recsound samplespersec " + sampleRate.ToString(), null, 0, IntPtr.Zero);
            mciSendString("set recsound channels " + channels.ToString(), null, 0, IntPtr.Zero);
            mciSendString("set recsound format pcm", null, 0, IntPtr.Zero);
            mciSendString("record recsound", null, 0, IntPtr.Zero);

        }


Mi dite che devo cambiare e se funziona su windows 7 ?.

Perché registrando cosi mi salva il file ad 88kbps.

Mi sapete dire come fare?
grazie mille.
30/10/10 21:00
TheKaneB
sicuro di voler salvare un file wave a 8 MHz? nemmeno i pipistrelli sentono quelle frequenze...
aaa
30/10/10 21:01
non saprei , ma dovrei registrare a 128kpbs,
mi dici come devo fare?

grazie.
30/10/10 21:07
TheKaneB
Postato originariamente da luy:

non saprei , ma dovrei registrare a 128kpbs,
mi dici come devo fare?

grazie.


in wave non compresso (ovvero PCM standard)?

i parametri da usare, ricavati con la calcolatrice, sono:
1 canale
8 bit per campione
16 KHz di frequenza di campionamento

fanno 16.000 * 8 * 1 = 128.000 bit al secondo
aaa
31/10/10 11:40
Postato originariamente da TheKaneB:

Postato originariamente da luy:

non saprei , ma dovrei registrare a 128kpbs,
mi dici come devo fare?

grazie.


in wave non compresso (ovvero PCM standard)?

i parametri da usare, ricavati con la calcolatrice, sono:
1 canale
8 bit per campione
16 KHz di frequenza di campionamento

fanno 16.000 * 8 * 1 = 128.000 bit al secondo


si , basta che viene registrato ad 128kbps. perchè come ora mi registra ad 88kbps con i kbps sbagliati e funziona male il grafico spettro.

Mi dici come fare?
31/10/10 12:26
ciao, mi sai dire dalla classe che ho trovato, che formato devo registrare il wave?
che mi venga bene il grafico. perchè ora è un pacciugo è non si capisce niente.
invece avevo provato con naudio e lui registandolo ad 128kbps mi faceva bene il grafico che ho fatto con la mia funzione.
using System;
using System.Collections.Generic;
using System.Text;
using System.IO;

namespace kr2000
{
    public class WaveReader
    {
        public Int32[][] Data { get; private set; }
        public int CompressionCode { get; private set; }
        public int NumberOfChannels { get; private set; }
        public int SampleRate { get; private set; }
        public int AverageBytesPerSecond { get; private set; }
        public int SignificantBitsPerSample { get; private set; }
        public int BlockAlign { get; private set; }
        public int Frames { get; private set; }
        public double TimeLength { get; private set; }

        /// <summary>
        /// Reads a Wave file from the input stream, but don't closes the stream
        /// </summary>
        /// <param name="stream">Input WAVE file stream</param>
        public WaveReader(Stream stream)
        {
            BinaryReader br = new BinaryReader(stream);
            try
            {
                if (new string(br.ReadChars(4)).ToUpper() == "RIFF")
                {
                    int length = br.ReadInt32();
                    if (new string(br.ReadChars(4)).ToUpper() == "WAVE")
                    {
                        string chunkName = new string(br.ReadChars(4)); //"fmt "
                        int chunkLength = br.ReadInt32();
                        this.CompressionCode = br.ReadInt16(); //1 for PCM/uncompressed
                        this.NumberOfChannels = br.ReadInt16();
                        this.SampleRate = br.ReadInt32();
                        this.AverageBytesPerSecond = br.ReadInt32();
                        this.BlockAlign = br.ReadInt16();
                        this.SignificantBitsPerSample = br.ReadInt16();
                        if (this.SignificantBitsPerSample == 0)
                            throw new Exception("The input stream uses an unhandled SignificantBitsPerSample parameter");
                        if (chunkLength > 16)
                        {
                            br.ReadChars(chunkLength - 16);
                        }
                        chunkName = new string(br.ReadChars(4));
                        try
                        {
                            while (chunkName.ToLower() != "data")
                            {
                                br.ReadChars(br.ReadInt32());
                                chunkName = new string(br.ReadChars(4));
                            }
                        }
                        catch
                        {
                            throw new Exception("Input stream misses the data chunk");
                        }
                        chunkLength = br.ReadInt32();
                        try
                        {
                            this.Frames = 8 * (chunkLength / this.SignificantBitsPerSample) / this.NumberOfChannels;
                        }
                        catch
                        {
                            throw new Exception("The input stream has zero channels");
                        }
                        this.TimeLength = ((double)this.Frames) / ((double)this.SampleRate);
                        this.Data = new Int32[this.NumberOfChannels][];
                        for (int j = 0; j < this.NumberOfChannels; j++)
                        {
                            this.Data[j] = new Int32[this.Frames];
                        }
                        switch (SignificantBitsPerSample)
                        {
                            case 4:
                                Byte b = new Byte();
                                bool IsEven = true;
                                for (int i = 0; i < this.Frames; i++)
                                {
                                    for (int j = 0; j < this.NumberOfChannels; j++)
                                    {
                                        if (IsEven)
                                        {
                                            b = br.ReadByte();
                                            Data[j][i] = Convert.ToInt32((b >> 4) & 0x0F);
                                        }
                                        else
                                        {
                                            Data[j][i] = Convert.ToInt32(b & 0x0F);
                                        }
                                        IsEven = !IsEven;
                                    }
                                }
                                break;
                            case 8:
                                for (int i = 0; i < this.Frames; i++)
                                {
                                    for (int j = 0; j < this.NumberOfChannels; j++)
                                    {
                                        Data[j][i] = Convert.ToInt32(br.ReadByte());
                                    }
                                }
                                break;
                            case 16:
                                for (int i = 0; i < this.Frames; i++)
                                {
                                    for (int j = 0; j < this.NumberOfChannels; j++)
                                    {
                                        Data[j][i] = br.ReadInt16();
                                    }
                                }
                                break;
                            case 24:
                                for (int i = 0; i < this.Frames; i++)
                                {
                                    for (int j = 0; j < this.NumberOfChannels; j++)
                                    {
                                        Byte[] int24 = br.ReadBytes(3);
                                        Data[j][i] = Convert.ToInt32(int24[0]) + (Convert.ToInt32(int24[1])<<8) + (Convert.ToInt32(int24[3])<<16);
                                    }
                                }
                                break;
                            case 32:
                                for (int i = 0; i < Frames; i++)
                                {
                                    for (int j = 0; j < this.NumberOfChannels; j++)
                                    {
                                        Data[j][i] = br.ReadInt32();
                                    }
                                }
                                break;
                            default:
                                throw new Exception("The input stream uses an unhandled SignificantBitsPerSample parameter");
                        }
                    }
                    else
                    {
                        throw new Exception("Input stream doesn't comply with the WAVE specification");
                    }
                }
                else
                {
                    throw new Exception("Input stream doesn't comply with the RIFF specification");
                }
            }
            finally
            {
                br.Close();
            }
        }
    }
}


grazie mille.
Ultima modifica effettuata da 31/10/10 12:27
31/10/10 13:25
TheKaneB
ti ho già detto quali parametri usare, cos'altro ti serve?
aaa
31/10/10 14:15
Postato originariamente da TheKaneB:

ti ho già detto quali parametri usare, cos'altro ti serve?


e nel mio caso cosa devo scrivere qui:
#
int sampleResolution = 16;
#
            int sampleRate = 44100;
#
            int channels = 2;

Grazie.