Thông báo

Collapse
No announcement yet.

tạo nhạc đơn âm phát bằng dsk 6416

Collapse
X
 
  • Lọc
  • Giờ
  • Show
Clear All
new posts

  • tạo nhạc đơn âm phát bằng dsk 6416

    em mới tham khảo được cách làm tạo ra âm thanh bằng sóng sin nhưng chỉ phát ra một âm o e o e thôi à,e nghĩ là có thể tạo được nhiều âm thanh khác nhau phát ra cùng một lúc mà build rùi lum mà chẳng được gì hết,e yếu c nên ngu cái khoảng này lắm,mong các bro góp ý giùm e với nha
    /*
    * C Function Prototypes
    */
    short sineGen(void);

    /*
    * DSP/BIOS is configured using the DSP/BIOS configuration tool. Settings
    * for this example are stored in a configuration file called tone.cdb. At
    * compile time, Code Composer will auto-generate DSP/BIOS related files
    * based on these settings. A header file called tonecfg.h contains the
    * results of the autogeneration and must be included for proper operation.
    * The name of the file is taken from tone.cdb and adding cfg.h.
    */
    #include "lab2cfg.h"

    /*
    * CSL Header Files
    */
    #include <csl.h>
    #include <csl_irq.h>

    /*
    * The 6416 (or C6713) DSK Board Support Library is divided into several modules,
    * each of which has its own include file. The file dsk6416.h (or dsk6713) must
    * be included in every program that uses the BSL. This example also includes
    * dsk6416_aic23.h because it uses the AIC23 codec module.
    */
    #include "dsk6416.h"
    #include "dsk6416_aic23.h"
    #include "dsk6416_dip.h"

    /*
    * Definitions
    */
    // To prevent the sine tone from being painfully loud when using
    // we program the headset volume field in the codec register to
    // be less than its maximum volume of 0x7f.
    # define headsetVol 0x01d0 // simul update | zero cross detect | headphone volume (0 (-71db) to 0x7f (+6db))
    // 0x100 | 0x0080 | 0x0050
    /*
    * Global Variables
    */
    // Codec configuration settings
    DSK6416_AIC23_Config config = { \
    0x0017, /* 0 DSK6416_AIC23_LEFTINVOL Left line input channel volume */ \
    0x0017, /* 1 DSK6416_AIC23_RIGHTINVOL Right line input channel volume */\
    headsetVol, /* 2 DSK6416_AIC23_LEFTHPVOL Left channel headphone vol */ \
    headsetVol, /* 3 DSK6416_AIC23_RIGHTHPVOL Right channel headphone vol */ \
    0x0011, /* 4 DSK6416_AIC23_ANAPATH Analog audio path control */ \
    0x0000, /* 5 DSK6416_AIC23_DIGPATH Digital audio path control */ \
    0x0000, /* 6 DSK6416_AIC23_POWERDOWN Power down control */ \
    0x0043, /* 7 DSK6416_AIC23_DIGIF Digital audio interface format */ \
    0x0081, /* 8 DSK6416_AIC23_SAMPLERATE Sample rate control */ \
    0x0001 /* 9 DSK6416_AIC23_DIGACT Digital interface activation */ \
    };

    // Declare BSL Handle for AIC23 Codec
    DSK6416_AIC23_CodecHandle hCodec;

    /*
    * main() - Main code routine, initializes BSL and a hardware interrupt
    */
    void main()
    {
    // Initialize the board support library, this must be called first
    DSK6416_init();

    // Open the codec
    hCodec = DSK6416_AIC23_openCodec(0, &config);

    // Enable the McBSP interrupt for IRQ_EVT_XINT2 (for 6416 DSK)
    // Enable the McBSP interrupt for IRQ_EVT_XINT1 (for 6713 DSK)
    IRQ_enable(IRQ_EVT_XINT2);

    // Invoke DSP/BIOS scheduler
    return;
    }


    /*
    * myHWI() - ISR called when the McBSP wants more data
    */
    void myHWI(void)
    {
    static short mySample;
    static int leftChan = 1;

    if(leftChan) {
    mySample = sineGen();
    leftChan = 0;
    }
    else {
    leftChan = 1;
    }

    // If DIP switch 0 is down (i.e. on), then play sinewave
    if (DSK6416_DIP_get(0) == 1){
    mySample = 0;
    }

    // Send a sample to the McBSP (which then sends it to the AIC23 codec)
    DSK6416_AIC23_write(hCodec, mySample);
    }
    cảm ơn chân thành sự góp ý của mọi người,đây là file phát ra âm lấy từ block_sine còn đây là file tạo sóng sin phát ra âm thanh
    // ======== block_sine.c =================================
    // The coefficient A and the three initial values
    // generate a 500Hz tone (sine wave) when running
    // at a sample rate of 48KHz.
    //
    // Even though the calculations are done in floating
    // point, this function returns a short value since
    // this is what's needed by a 16-bit codec (DAC).

    // ======== Prototypes ===================================
    void blockSine(short *buf, int len);
    short sineGen(void);

    // ======== Definitions ==================================
    // Initial values
    #define Y1 0.0654031 // = sin((f_tone/f_samp) * 360)
    // = sin((500Hz / 48KHz) * 360)
    // = sin (3.75)
    #define AA 1.9957178 // = 2 * cos(3.75)

    // ======== Globals =====================================
    static float y[3] = {0,Y1,0};
    static float A = AA;

    // ======== sineGen ======================================
    // Generate a single element of sine data
    short sineGen(void)
    {
    y[0] = y[1] * A - y[2];
    y[2] = y[1];
    y[1] = y[0];

    // To scale full 16-bit range we would multiply y[0]
    // by 32768 using a number slightly less than this
    // (such as 32000) helps to prevent overflow.
    y[0] *= 32000;

    // We recast the result to a short value upon returning it
    // since the D/A converter is programmed to accept 16-bit
    // signed values.
    return((short)y[0]);
    }

    // ======== blockSine ========
    // Generate a block of sine data using sineGen
    void blockSine(short *buf, int len)
    {
    int i = 0;

    for (i = 0;i < len; i++) {
    buf[i] = sineGen();
    }
    }

  • #2
    nếu nhự bạn muốn phát một bản nhạc đơn âm thì bạn phải tìm hiểu về tone của các nốt nhạc, từ đó tạo ra sóng sine có tần số của các tone đó, sau khi tạo được tone tướng ứng vỡi mỗi nốt nhạc, kế tiếp bạn phải biết cách phối hợp các tone đó lại, tạo tiếng ngân bằng cách kéo dài tone, rồi điều chỉnh biên độ của tone để có được một bản nhạc theo ý muốn! cái này gần giống với phương pháp tỉa đàn guitar ấy, có điều biểu diễn nó bằng ngôn ngữ C thì hơi cực

    Comment


    • #3
      cảm ơn bạn,đúng là khó thiệt,đang bù đầu suy nghĩ,mong có thêm lời góp ý của mọi người ^^

      Comment


      • #4
        mọi người vô cho ý kiền giùm e với nha,cảm ơn mọi người

        Comment


        • #5
          ??? cứ thế mà tiến hành thôi, dựa theo bảng tần số của từng nốt nhạc mà phát . ý kiến ý cò gì nữa!!!!, nếu cảm thấy tạo sóng sine khó thì sử dụng phuơng pháp biến đổi F ngược rồi rút ra các giá trị của bảng sine, sau đó lấy các giá trị đó tiến hành output ra DAC.

          Comment

          Về tác giả

          Collapse

          hitman2607 Tìm hiểu thêm về hitman2607

          Bài viết mới nhất

          Collapse

          Đang tải...
          X