Click here to Skip to main content
15,898,134 members
Articles / Web Development / HTML

How to change the pitch and tempo of a sound

Rate me:
Please Sign up or sign in to vote.
4.91/5 (34 votes)
24 Sep 2011LGPL36 min read 196K   14.9K   71  
This article shows how to change the pitch and tempo of a sound.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.InteropServices;

namespace CpctDotNetDll
{
    public class CpctDotNet
    {
#region Members
        private IntPtr m_handle = IntPtr.Zero;
#endregion

#region Native C++ API Methods
        private const string DllName = "cpct_dll.dll";

        [DllImport(DllName)]
        private static extern IntPtr createCpctByDefault();

        [DllImport(DllName)]
        private static extern IntPtr createCpctByParams(int winlen, int hoplen, int nit);

        [DllImport(DllName)]
        private static extern void setData(IntPtr h, [MarshalAs(UnmanagedType.LPArray)] float[] data, int datalength, int nChannels);

        [DllImport(DllName)]
        private static extern void setParams(IntPtr h, float tempo, float pitch);

        [DllImport(DllName)]
        private static extern void getData(IntPtr h, [MarshalAs(UnmanagedType.LPArray)] float[] data, out int datalength);

        [DllImport(DllName)]
        private static extern void destroyCpct(IntPtr h);

#endregion

#region C# Wrapper Methods
        /// <summary>
        /// 
        /// </summary>
        public void CreateCpctByDefault()
        {
            m_handle = createCpctByDefault();
        }

        public void CreateCpctByParams(int winlen, int hoplen, int nit)
        {
            m_handle = createCpctByParams(winlen, hoplen, nit);
        }

        public void SetData(float[] data, int datalength, int nChannels)
        {
            setData(m_handle, data, datalength, nChannels);
        }

        public void SetParams(float tempo, float pitch)
        {
            setParams(m_handle, tempo, pitch);
        }

        public void GetData(float[] data, out int datalength)
        {
            getData(m_handle, data, out datalength);
        }

        public void DestroyCpct()
        {
            destroyCpct(m_handle);
        }
#endregion
    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The GNU Lesser General Public License (LGPLv3)


Written By
China China
E-mail:calinyara@gmail.com

Comments and Discussions