Questo sito utilizza cookies solo per scopi di autenticazione sul sito e nient'altro. Nessuna informazione personale viene tracciata. Leggi l'informativa sui cookies.
Username: Password: oppure
C# / VB.NET - mci registrare ad 128kbps e 8mhz
Forum - C# / VB.NET - mci registrare ad 128kbps e 8mhz

Pagine: [ 1 2 ] Precedente | Prossimo
Avatar
()
Newbie


Messaggi:
Iscritto:

Segnala al moderatore
Postato alle 1:00
Giovedì, 01/01/1970
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:

Codice sorgente - presumibilmente C#

  1. public void OpenMic()
  2.         {
  3.             int sampleResolution = 16;
  4.             int sampleRate = 44100;
  5.             int channels = 2;
  6.  
  7.             mciSendString("open new Type waveaudio Alias recsound", null, 0, IntPtr.Zero);
  8.             mciSendString("set recsound bitspersample " + sampleResolution.ToString(), null, 0, IntPtr.Zero);
  9.             mciSendString("set recsound samplespersec " + sampleRate.ToString(), null, 0, IntPtr.Zero);
  10.             mciSendString("set recsound channels " + channels.ToString(), null, 0, IntPtr.Zero);
  11.             mciSendString("set recsound format pcm", null, 0, IntPtr.Zero);
  12.             mciSendString("record recsound", null, 0, IntPtr.Zero);
  13.  
  14.         }



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.

PM Quote
Avatar
TheKaneB (Member)
Guru^2


Messaggi: 1792
Iscritto: 26/06/2009

Segnala al moderatore
Postato alle 23:00
Sabato, 30/10/2010
sicuro di voler salvare un file wave a 8 MHz? nemmeno i pipistrelli sentono quelle frequenze...

PM Quote
Avatar
()
Newbie


Messaggi:
Iscritto:

Segnala al moderatore
Postato alle 23:01
Sabato, 30/10/2010
non saprei , ma dovrei registrare a 128kpbs,
mi dici come devo fare?

grazie.

PM Quote
Avatar
TheKaneB (Member)
Guru^2


Messaggi: 1792
Iscritto: 26/06/2009

Segnala al moderatore
Postato alle 23:07
Sabato, 30/10/2010
Testo quotato

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

PM Quote
Avatar
()
Newbie


Messaggi:
Iscritto:

Segnala al moderatore
Postato alle 12:40
Domenica, 31/10/2010
Testo quotato

Postato originariamente da TheKaneB:

Testo quotato

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?

PM Quote
Avatar
()
Newbie


Messaggi:
Iscritto:

Segnala al moderatore
Postato alle 13:26
Domenica, 31/10/2010
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.
Codice sorgente - presumibilmente C++

  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text;
  4. using System.IO;
  5.  
  6. namespace kr2000
  7. {
  8.     public class WaveReader
  9.     {
  10.         public Int32[][] Data { get; private set; }
  11.         public int CompressionCode { get; private set; }
  12.         public int NumberOfChannels { get; private set; }
  13.         public int SampleRate { get; private set; }
  14.         public int AverageBytesPerSecond { get; private set; }
  15.         public int SignificantBitsPerSample { get; private set; }
  16.         public int BlockAlign { get; private set; }
  17.         public int Frames { get; private set; }
  18.         public double TimeLength { get; private set; }
  19.  
  20.         /// <summary>
  21.         /// Reads a Wave file from the input stream, but don't closes the stream
  22.         /// </summary>
  23.         /// <param name="stream">Input WAVE file stream</param>
  24.         public WaveReader(Stream stream)
  25.         {
  26.             BinaryReader br = new BinaryReader(stream);
  27.             try
  28.             {
  29.                 if (new string(br.ReadChars(4)).ToUpper() == "RIFF")
  30.                 {
  31.                     int length = br.ReadInt32();
  32.                     if (new string(br.ReadChars(4)).ToUpper() == "WAVE")
  33.                     {
  34.                         string chunkName = new string(br.ReadChars(4)); //"fmt "
  35.                         int chunkLength = br.ReadInt32();
  36.                         this.CompressionCode = br.ReadInt16(); //1 for PCM/uncompressed
  37.                         this.NumberOfChannels = br.ReadInt16();
  38.                         this.SampleRate = br.ReadInt32();
  39.                         this.AverageBytesPerSecond = br.ReadInt32();
  40.                         this.BlockAlign = br.ReadInt16();
  41.                         this.SignificantBitsPerSample = br.ReadInt16();
  42.                         if (this.SignificantBitsPerSample == 0)
  43.                             throw new Exception("The input stream uses an unhandled SignificantBitsPerSample parameter");
  44.                         if (chunkLength > 16)
  45.                         {
  46.                             br.ReadChars(chunkLength - 16);
  47.                         }
  48.                         chunkName = new string(br.ReadChars(4));
  49.                         try
  50.                         {
  51.                             while (chunkName.ToLower() != "data")
  52.                             {
  53.                                 br.ReadChars(br.ReadInt32());
  54.                                 chunkName = new string(br.ReadChars(4));
  55.                             }
  56.                         }
  57.                         catch
  58.                         {
  59.                             throw new Exception("Input stream misses the data chunk");
  60.                         }
  61.                         chunkLength = br.ReadInt32();
  62.                         try
  63.                         {
  64.                             this.Frames = 8 * (chunkLength / this.SignificantBitsPerSample) / this.NumberOfChannels;
  65.                         }
  66.                         catch
  67.                         {
  68.                             throw new Exception("The input stream has zero channels");
  69.                         }
  70.                         this.TimeLength = ((double)this.Frames) / ((double)this.SampleRate);
  71.                         this.Data = new Int32[this.NumberOfChannels][];
  72.                         for (int j = 0; j < this.NumberOfChannels; j++)
  73.                         {
  74.                             this.Data[j] = new Int32[this.Frames];
  75.                         }
  76.                         switch (SignificantBitsPerSample)
  77.                         {
  78.                             case 4:
  79.                                 Byte b = new Byte();
  80.                                 bool IsEven = true;
  81.                                 for (int i = 0; i < this.Frames; i++)
  82.                                 {
  83.                                     for (int j = 0; j < this.NumberOfChannels; j++)
  84.                                     {
  85.                                         if (IsEven)
  86.                                         {
  87.                                             b = br.ReadByte();
  88.                                             Data[j][i] = Convert.ToInt32((b >> 4) & 0x0F);
  89.                                         }
  90.                                         else
  91.                                         {
  92.                                             Data[j][i] = Convert.ToInt32(b & 0x0F);
  93.                                         }
  94.                                         IsEven = !IsEven;
  95.                                     }
  96.                                 }
  97.                                 break;
  98.                             case 8:
  99.                                 for (int i = 0; i < this.Frames; i++)
  100.                                 {
  101.                                     for (int j = 0; j < this.NumberOfChannels; j++)
  102.                                     {
  103.                                         Data[j][i] = Convert.ToInt32(br.ReadByte());
  104.                                     }
  105.                                 }
  106.                                 break;
  107.                             case 16:
  108.                                 for (int i = 0; i < this.Frames; i++)
  109.                                 {
  110.                                     for (int j = 0; j < this.NumberOfChannels; j++)
  111.                                     {
  112.                                         Data[j][i] = br.ReadInt16();
  113.                                     }
  114.                                 }
  115.                                 break;
  116.                             case 24:
  117.                                 for (int i = 0; i < this.Frames; i++)
  118.                                 {
  119.                                     for (int j = 0; j < this.NumberOfChannels; j++)
  120.                                     {
  121.                                         Byte[] int24 = br.ReadBytes(3);
  122.                                         Data[j][i] = Convert.ToInt32(int24[0]) + (Convert.ToInt32(int24[1])<<8) + (Convert.ToInt32(int24[3])<<16);
  123.                                     }
  124.                                 }
  125.                                 break;
  126.                             case 32:
  127.                                 for (int i = 0; i < Frames; i++)
  128.                                 {
  129.                                     for (int j = 0; j < this.NumberOfChannels; j++)
  130.                                     {
  131.                                         Data[j][i] = br.ReadInt32();
  132.                                     }
  133.                                 }
  134.                                 break;
  135.                             default:
  136.                                 throw new Exception("The input stream uses an unhandled SignificantBitsPerSample parameter");
  137.                         }
  138.                     }
  139.                     else
  140.                     {
  141.                         throw new Exception("Input stream doesn't comply with the WAVE specification");
  142.                     }
  143.                 }
  144.                 else
  145.                 {
  146.                     throw new Exception("Input stream doesn't comply with the RIFF specification");
  147.                 }
  148.             }
  149.             finally
  150.             {
  151.                 br.Close();
  152.             }
  153.         }
  154.     }
  155. }



grazie mille.

Ultima modifica effettuata da il 31/10/2010 alle 13:27
PM Quote
Avatar
TheKaneB (Member)
Guru^2


Messaggi: 1792
Iscritto: 26/06/2009

Segnala al moderatore
Postato alle 14:25
Domenica, 31/10/2010
ti ho già detto quali parametri usare, cos'altro ti serve?

PM Quote
Avatar
()
Newbie


Messaggi:
Iscritto:

Segnala al moderatore
Postato alle 15:15
Domenica, 31/10/2010
Testo quotato

Postato originariamente da TheKaneB:

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



e nel mio caso cosa devo scrivere qui:
Codice sorgente - presumibilmente C# / VB.NET

  1. #
  2. int sampleResolution = 16;
  3. #
  4.             int sampleRate = 44100;
  5. #
  6.             int channels = 2;


Grazie.

PM Quote
Avatar
TheKaneB (Member)
Guru^2


Messaggi: 1792
Iscritto: 26/06/2009

Segnala al moderatore
Postato alle 15:25
Domenica, 31/10/2010
Testo quotato

Postato originariamente da TheKaneB:

Testo quotato

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



:pat:

PM Quote
Pagine: [ 1 2 ] Precedente | Prossimo