Tôi muốn tạo hệ thống hình ảnh hóa âm thanh bằng ngôn ngữ C# và .NET Framework. Điều này có thể giống như trong ứng dụng Winamp. Có thể tồn tại thư viện miễn phí hoặc một số bài viết thú vị mô tả cách thực hiện? Ví dụ: alt text http://img44.imageshack.us/img44/9982/examplel.pngHình ảnh hóa âm thanh C#
Trả lời
Bạn có thể thử những liên kết này
OpenVP (là một nền tảng miễn phí và mã nguồn mở để phát triển visualizations âm nhạc, viết bằng C#), xem OpenVP Screenshots.
Play and Visualize WAV Files using Managed Direct Sound
Bye.
Đây là tập lệnh tính toán FFT của bất kỳ âm thanh nào được phát trên máy tính bằng API WASAPI. Nó sử dụng CSCore và WinformsVisualization dụ của nó:
using CSCore;
using CSCore.SoundIn;
using CSCore.Codecs.WAV;
using WinformsVisualization.Visualization;
using CSCore.DSP;
using CSCore.Streams;
using System;
public class SoundCapture
{
public int numBars = 30;
public int minFreq = 5;
public int maxFreq = 4500;
public int barSpacing = 0;
public bool logScale = true;
public bool isAverage = false;
public float highScaleAverage = 2.0f;
public float highScaleNotAverage = 3.0f;
LineSpectrum lineSpectrum;
WasapiCapture capture;
WaveWriter writer;
FftSize fftSize;
float[] fftBuffer;
SingleBlockNotificationStream notificationSource;
BasicSpectrumProvider spectrumProvider;
IWaveSource finalSource;
public SoundCapture()
{
// This uses the wasapi api to get any sound data played by the computer
capture = new WasapiLoopbackCapture();
capture.Initialize();
// Get our capture as a source
IWaveSource source = new SoundInSource(capture);
// From https://github.com/filoe/cscore/blob/master/Samples/WinformsVisualization/Form1.cs
// This is the typical size, you can change this for higher detail as needed
fftSize = FftSize.Fft4096;
// Actual fft data
fftBuffer = new float[(int)fftSize];
// These are the actual classes that give you spectrum data
// The specific vars of lineSpectrum here aren't that important because they can be changed by the user
spectrumProvider = new BasicSpectrumProvider(capture.WaveFormat.Channels,
capture.WaveFormat.SampleRate, fftSize);
lineSpectrum = new LineSpectrum(fftSize)
{
SpectrumProvider = spectrumProvider,
UseAverage = true,
BarCount = numBars,
BarSpacing = 2,
IsXLogScale = false,
ScalingStrategy = ScalingStrategy.Linear
};
// Tells us when data is available to send to our spectrum
var notificationSource = new SingleBlockNotificationStream(source.ToSampleSource());
notificationSource.SingleBlockRead += NotificationSource_SingleBlockRead;
// We use this to request data so it actualy flows through (figuring this out took forever...)
finalSource = notificationSource.ToWaveSource();
capture.DataAvailable += Capture_DataAvailable;
capture.Start();
}
private void Capture_DataAvailable(object sender, DataAvailableEventArgs e)
{
finalSource.Read(e.Data, e.Offset, e.ByteCount);
}
private void NotificationSource_SingleBlockRead(object sender, SingleBlockReadEventArgs e)
{
spectrumProvider.Add(e.Left, e.Right);
}
~SoundCapture()
{
capture.Stop();
capture.Dispose();
}
public float[] barData = new float[20];
public float[] GetFFtData()
{
lock (barData)
{
lineSpectrum.BarCount = numBars;
if (numBars != barData.Length)
{
barData = new float[numBars];
}
}
if (spectrumProvider.IsNewDataAvailable)
{
lineSpectrum.MinimumFrequency = minFreq;
lineSpectrum.MaximumFrequency = maxFreq;
lineSpectrum.IsXLogScale = logScale;
lineSpectrum.BarSpacing = barSpacing;
lineSpectrum.SpectrumProvider.GetFftData(fftBuffer, this);
return lineSpectrum.GetSpectrumPoints(100.0f, fftBuffer);
}
else
{
return null;
}
}
public void ComputeData()
{
float[] resData = GetFFtData();
int numBars = barData.Length;
if (resData == null)
{
return;
}
lock (barData)
{
for (int i = 0; i < numBars && i < resData.Length; i++)
{
// Make the data between 0.0 and 1.0
barData[i] = resData[i]/100.0f;
}
for (int i = 0; i < numBars && i < resData.Length; i++)
{
if (lineSpectrum.UseAverage)
{
// Scale the data because for some reason bass is always loud and treble is soft
barData[i] = barData[i] + highScaleAverage * (float)Math.Sqrt(i/(numBars + 0.0f)) * barData[i];
}
else
{
barData[i] = barData[i] + highScaleNotAverage * (float)Math.Sqrt(i/(numBars + 0.0f)) * barData[i];
}
}
}
}
}
Sau đó, khi lấy các barData từ một kịch bản khác nhau nó được đề nghị để khóa nó đầu tiên kể từ này được sửa đổi trên một sợi riêng biệt.
Tôi không chắc chắn nơi mình có GetSpectrumPoints
vì nó dường như không nằm trong số Github Repo, nhưng ở đây nó được. Chỉ cần dán vào tệp đó và mã của tôi sẽ hoạt động.
public float[] GetSpectrumPoints(float height, float[] fftBuffer)
{
SpectrumPointData[] dats = CalculateSpectrumPoints(height, fftBuffer);
float[] res = new float[dats.Length];
for (int i = 0; i < dats.Length; i++)
{
res[i] = (float)dats[i].Value;
}
return res;
}
Tôi đã cố gắng sử dụng mã ví dụ của bạn, nhưng dường như không có ['GetSpectrumPoints()' là một hàm nữa] (https://github.com/filoe/cscore/blob/29410b12ae35321c4556b072c0711a8f289c0544/Samples/ WinformsVisualization/Visualization/LineSpectrum.cs # L10) và kiểm tra lịch sử kho lưu trữ git cũng không hiển thị nó. Bạn có nhớ làm rõ/cập nhật câu trả lời của bạn không? (* Tôi đang cố gắng tích hợp thu/xử lý âm thanh trên Windows bằng ứng dụng giao diện điều khiển đa nền tảng để điều khiển đèn LED; các giá trị dữ liệu tần số từ 0.0 đến 1.0 là tất cả những gì cần *) – Shane
@Shane Rất tiếc! Tôi đã thêm mã đó ngay bây giờ, hy vọng sẽ giúp – Phylliida
- 1. Âm thanh nền - Hình ảnh trên màn hình khóa
- 2. Phát tệp âm thanh khi hình ảnh được nhấp
- 3. Tạo hình ảnh dạng sóng từ tệp âm thanh
- 4. mã hóa nhị phân thành python âm thanh hoặc C
- 5. Hợp âm âm thanh trong C#?
- 6. đồng bộ hóa âm thanh qua mạng
- 7. Xử lý âm thanh C++
- 8. Âm thanh máy trong C#
- 9. Nhận mảng byte âm thanh với API âm thanh HTML5?
- 10. âm thanh stegnography
- 11. Thư viện để lấy bản đồ độ sâu từ hình ảnh âm thanh nổi?
- 12. Âm thanh âm thanh định tuyến iPhone
- 13. Muốn tạo tệp video từ chuỗi hình ảnh và tệp âm thanh
- 14. Âm thanh/video không đồng bộ hóa sau khi chuyển đổi máy ảnh
- 15. c chương trình phát tệp âm thanh
- 16. Ghi Âm thanh Đầu ra Trong C#
- 17. Cách tạo âm thanh từ đầu C#
- 18. Phát hiện âm thanh vỗ tay trong C#
- 19. Khung tổng hợp âm thanh trong C/C++/Objective-C?
- 20. Mã hóa âm thanh thành aac bằng libavcodec
- 21. Tạo hình thu nhỏ cho tệp âm thanh tùy ý
- 22. Android: âm thanh thông báo vô hiệu hóa
- 23. Phát Âm thanh bằng HTML
- 24. Chuyển đổi hình ảnh âm thành dương
- 25. Tự động hóa từ: Thay thế hình ảnh bằng C#
- 26. Máy ảnh có âm thanh màn trập tùy chỉnh
- 27. Hiển thị sóng âm thanh để ghi âm
- 28. Hiển thị âm thanh/giọng nói
- 29. Phát âm thanh và âm thanh thuật toán
- 30. Phát luồng âm thanh an toàn bằng Âm thanh HTML5
Tôi nghĩ rằng nó sẽ là tốt để bắt đầu, cảm ơn. –