~vcs-imports/qemu/maemo

« back to all changes in this revision

Viewing changes to audio/audio.c

  • Committer: Riku Voipio
  • Date: 2009-06-08 15:31:58 UTC
  • mfrom: (6281.2.366)
  • mto: This revision was merged to the branch mainline in revision 6452.
  • Revision ID: git-v1:759b334a9739814df2883aa4c41b1c0f5670e90a
Merge commit 'gnu/master' into test

Epic merge

Conflicts:
        Makefile
        block.c
        block.h
        configure
        hw/boards.h
        hw/flash.h
        hw/integratorcp.c
        hw/nand.c
        hw/omap2.c
        hw/omap_i2c.c
        hw/sd.c
        hw/smc91c111.c
        hw/tsc2005.c
        hw/tusb6010.c
        hw/usb-musb.c
        linux-user/syscall.c
        target-arm/machine.c
        target-arm/translate.c

Show diffs side-by-side

added added

removed removed

Lines of Context:
707
707
}
708
708
 
709
709
static CaptureVoiceOut *audio_pcm_capture_find_specific (
710
 
    AudioState *s,
711
710
    struct audsettings *as
712
711
    )
713
712
{
714
713
    CaptureVoiceOut *cap;
 
714
    AudioState *s = &glob_audio_state;
715
715
 
716
716
    for (cap = s->cap_head.lh_first; cap; cap = cap->entries.le_next) {
717
717
        if (audio_pcm_info_eq (&cap->hw.info, as)) {
786
786
    }
787
787
}
788
788
 
789
 
static int audio_attach_capture (AudioState *s, HWVoiceOut *hw)
 
789
static int audio_attach_capture (HWVoiceOut *hw)
790
790
{
 
791
    AudioState *s = &glob_audio_state;
791
792
    CaptureVoiceOut *cap;
792
793
 
793
794
    audio_detach_capture (hw);
1295
1296
    HWVoiceOut *hw = NULL;
1296
1297
    SWVoiceOut *sw;
1297
1298
 
1298
 
    while ((hw = audio_pcm_hw_find_any_enabled_out (s, hw))) {
 
1299
    while ((hw = audio_pcm_hw_find_any_enabled_out (hw))) {
1299
1300
        int played;
1300
1301
        int live, free, nb_live, cleanup_required, prev_rpos;
1301
1302
 
1390
1391
#ifdef DEBUG_PLIVE
1391
1392
                    dolog ("Finishing with old voice\n");
1392
1393
#endif
1393
 
                    audio_close_out (s, sw);
 
1394
                    audio_close_out (sw);
1394
1395
                }
1395
1396
                sw = sw1;
1396
1397
            }
1402
1403
{
1403
1404
    HWVoiceIn *hw = NULL;
1404
1405
 
1405
 
    while ((hw = audio_pcm_hw_find_any_enabled_in (s, hw))) {
 
1406
    while ((hw = audio_pcm_hw_find_any_enabled_in (hw))) {
1406
1407
        SWVoiceIn *sw;
1407
1408
        int captured, min;
1408
1409
 
1610
1611
    s->drv_opaque = drv->init ();
1611
1612
 
1612
1613
    if (s->drv_opaque) {
1613
 
        audio_init_nb_voices_out (s, drv);
1614
 
        audio_init_nb_voices_in (s, drv);
 
1614
        audio_init_nb_voices_out (drv);
 
1615
        audio_init_nb_voices_in (drv);
1615
1616
        s->drv = drv;
1616
1617
        return 0;
1617
1618
    }
1630
1631
    int op = running ? VOICE_ENABLE : VOICE_DISABLE;
1631
1632
 
1632
1633
    s->vm_running = running;
1633
 
    while ((hwo = audio_pcm_hw_find_any_enabled_out (s, hwo))) {
 
1634
    while ((hwo = audio_pcm_hw_find_any_enabled_out (hwo))) {
1634
1635
        hwo->pcm_ops->ctl_out (hwo, op);
1635
1636
    }
1636
1637
 
1637
 
    while ((hwi = audio_pcm_hw_find_any_enabled_in (s, hwi))) {
 
1638
    while ((hwi = audio_pcm_hw_find_any_enabled_in (hwi))) {
1638
1639
        hwi->pcm_ops->ctl_in (hwi, op);
1639
1640
    }
1640
1641
}
1645
1646
    HWVoiceOut *hwo = NULL;
1646
1647
    HWVoiceIn *hwi = NULL;
1647
1648
 
1648
 
    while ((hwo = audio_pcm_hw_find_any_enabled_out (s, hwo))) {
 
1649
    while ((hwo = audio_pcm_hw_find_any_enabled_out (hwo))) {
1649
1650
        SWVoiceCap *sc;
1650
1651
 
1651
1652
        hwo->pcm_ops->ctl_out (hwo, VOICE_DISABLE);
1661
1662
        }
1662
1663
    }
1663
1664
 
1664
 
    while ((hwi = audio_pcm_hw_find_any_enabled_in (s, hwi))) {
 
1665
    while ((hwi = audio_pcm_hw_find_any_enabled_in (hwi))) {
1665
1666
        hwi->pcm_ops->ctl_in (hwi, VOICE_DISABLE);
1666
1667
        hwi->pcm_ops->fini_in (hwi);
1667
1668
    }
1689
1690
    return 0;
1690
1691
}
1691
1692
 
1692
 
void AUD_register_card (AudioState *s, const char *name, QEMUSoundCard *card)
1693
 
{
1694
 
    card->audio = s;
1695
 
    card->name = qemu_strdup (name);
1696
 
    memset (&card->entries, 0, sizeof (card->entries));
1697
 
    LIST_INSERT_HEAD (&s->card_head, card, entries);
1698
 
}
1699
 
 
1700
 
void AUD_remove_card (QEMUSoundCard *card)
1701
 
{
1702
 
    LIST_REMOVE (card, entries);
1703
 
    card->audio = NULL;
1704
 
    qemu_free (card->name);
1705
 
}
1706
 
 
1707
 
AudioState *AUD_init (void)
 
1693
static void audio_init (void)
1708
1694
{
1709
1695
    size_t i;
1710
1696
    int done = 0;
1711
1697
    const char *drvname;
1712
1698
    AudioState *s = &glob_audio_state;
1713
1699
 
 
1700
    if (s->drv) {
 
1701
        return;
 
1702
    }
 
1703
 
1714
1704
    LIST_INIT (&s->hw_head_out);
1715
1705
    LIST_INIT (&s->hw_head_in);
1716
1706
    LIST_INIT (&s->cap_head);
1718
1708
 
1719
1709
    s->ts = qemu_new_timer (vm_clock, audio_timer, s);
1720
1710
    if (!s->ts) {
1721
 
        dolog ("Could not create audio timer\n");
1722
 
        return NULL;
 
1711
        hw_error("Could not create audio timer\n");
1723
1712
    }
1724
1713
 
1725
1714
    audio_process_options ("AUDIO", audio_options);
1772
1761
    if (!done) {
1773
1762
        done = !audio_driver_init (s, &no_audio_driver);
1774
1763
        if (!done) {
1775
 
            dolog ("Could not initialize audio subsystem\n");
 
1764
            hw_error("Could not initialize audio subsystem\n");
1776
1765
        }
1777
1766
        else {
1778
1767
            dolog ("warning: Using timer based audio emulation\n");
1779
1768
        }
1780
1769
    }
1781
1770
 
1782
 
    if (done) {
1783
 
        VMChangeStateEntry *e;
1784
 
 
1785
 
        if (conf.period.hertz <= 0) {
1786
 
            if (conf.period.hertz < 0) {
1787
 
                dolog ("warning: Timer period is negative - %d "
1788
 
                       "treating as zero\n",
1789
 
                       conf.period.hertz);
1790
 
            }
1791
 
            conf.period.ticks = 1;
1792
 
        }
1793
 
        else {
1794
 
            conf.period.ticks = ticks_per_sec / conf.period.hertz;
1795
 
        }
1796
 
 
1797
 
        e = qemu_add_vm_change_state_handler (audio_vm_change_state_handler, s);
1798
 
        if (!e) {
1799
 
            dolog ("warning: Could not register change state handler\n"
1800
 
                   "(Audio can continue looping even after stopping the VM)\n");
1801
 
        }
 
1771
    VMChangeStateEntry *e;
 
1772
 
 
1773
    if (conf.period.hertz <= 0) {
 
1774
        if (conf.period.hertz < 0) {
 
1775
            dolog ("warning: Timer period is negative - %d "
 
1776
                   "treating as zero\n",
 
1777
                   conf.period.hertz);
 
1778
        }
 
1779
        conf.period.ticks = 1;
 
1780
    } else {
 
1781
        conf.period.ticks = ticks_per_sec / conf.period.hertz;
1802
1782
    }
1803
 
    else {
1804
 
        qemu_del_timer (s->ts);
1805
 
        return NULL;
 
1783
 
 
1784
    e = qemu_add_vm_change_state_handler (audio_vm_change_state_handler, s);
 
1785
    if (!e) {
 
1786
        dolog ("warning: Could not register change state handler\n"
 
1787
               "(Audio can continue looping even after stopping the VM)\n");
1806
1788
    }
1807
1789
 
1808
1790
    LIST_INIT (&s->card_head);
1809
1791
    register_savevm ("audio", 0, 1, audio_save, audio_load, s);
1810
1792
    qemu_mod_timer (s->ts, qemu_get_clock (vm_clock) + conf.period.ticks);
1811
 
    return s;
1812
 
}
 
1793
}
 
1794
 
 
1795
void AUD_register_card (const char *name, QEMUSoundCard *card)
 
1796
{
 
1797
    audio_init ();
 
1798
    card->name = qemu_strdup (name);
 
1799
    memset (&card->entries, 0, sizeof (card->entries));
 
1800
    LIST_INSERT_HEAD (&glob_audio_state.card_head, card, entries);
 
1801
}
 
1802
 
 
1803
void AUD_remove_card (QEMUSoundCard *card)
 
1804
{
 
1805
    LIST_REMOVE (card, entries);
 
1806
    qemu_free (card->name);
 
1807
}
 
1808
 
1813
1809
 
1814
1810
CaptureVoiceOut *AUD_add_capture (
1815
 
    AudioState *s,
1816
1811
    struct audsettings *as,
1817
1812
    struct audio_capture_ops *ops,
1818
1813
    void *cb_opaque
1819
1814
    )
1820
1815
{
 
1816
    AudioState *s = &glob_audio_state;
1821
1817
    CaptureVoiceOut *cap;
1822
1818
    struct capture_callback *cb;
1823
1819
 
1824
 
    if (!s) {
1825
 
        /* XXX suppress */
1826
 
        s = &glob_audio_state;
1827
 
    }
1828
 
 
1829
1820
    if (audio_validate_settings (as)) {
1830
1821
        dolog ("Invalid settings were passed when trying to add capture\n");
1831
1822
        audio_print_settings (as);
1841
1832
    cb->ops = *ops;
1842
1833
    cb->opaque = cb_opaque;
1843
1834
 
1844
 
    cap = audio_pcm_capture_find_specific (s, as);
 
1835
    cap = audio_pcm_capture_find_specific (as);
1845
1836
    if (cap) {
1846
1837
        LIST_INSERT_HEAD (&cap->cb_head, cb, entries);
1847
1838
        return cap;
1891
1882
        LIST_INSERT_HEAD (&cap->cb_head, cb, entries);
1892
1883
 
1893
1884
        hw = NULL;
1894
 
        while ((hw = audio_pcm_hw_find_any_out (s, hw))) {
1895
 
            audio_attach_capture (s, hw);
 
1885
        while ((hw = audio_pcm_hw_find_any_out (hw))) {
 
1886
            audio_attach_capture (hw);
1896
1887
        }
1897
1888
        return cap;
1898
1889